Advertisement
Argintos

Untitled

Apr 20th, 2014
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <conio.h>
  4.  
  5. using namespace std;
  6. const int ratingSize = 5;
  7. struct Students
  8. {
  9.     char name[20];
  10.     int groupId;
  11.     int rating[ratingSize];
  12. };
  13.  
  14. int main()
  15. {
  16.     FILE *fileRead;
  17.  
  18.     char* filePath = new char[];
  19.  
  20.     cout << "Filepath: ";
  21.     gets(filePath);
  22.  
  23.     while(!(fileRead = fopen(filePath, "r")))
  24.     {
  25.         cout << "Wrong filepath, try again ";
  26.         cout << endl;
  27.         cout << "Filepath: ";
  28.         gets(filePath);
  29.     }
  30.  
  31.     int sizeGroup = 4;
  32.     const int sizeBuffer = 1000;
  33.     char buffer[sizeBuffer];
  34.     int temp;
  35.  
  36.     Students* group = new Students[sizeGroup];
  37.  
  38.     for (int i = 0; i < sizeGroup; i++)
  39.     {
  40.         temp = 25;
  41.         fgets(buffer, sizeBuffer, fileRead);
  42.         strncpy(group[i].name, buffer, 19);
  43.         group[i].name[19] = '\0';
  44.         group[i].groupId = atoi(&buffer[20]);
  45.         cout << endl << "Name: " << group[i].name << endl;
  46.         cout << "Group Id: " << group[i].groupId << endl;
  47.         cout << "Rating: ";
  48.         for (int j = 0; j < ratingSize; j++)
  49.         {
  50.             group[i].rating[j] = atoi(&buffer[temp]);
  51.             temp+=5;
  52.             cout << group[i].rating[j] << " ";
  53.         }
  54.         cout << endl;
  55.     }
  56.     fclose(fileRead);
  57.  
  58.     _getch();
  59.     return 0;
  60. }
  61.  
  62. //Ivanov I.I.         45   5    4    3    4    4
  63. //Petrov P.P.         15   3    3    4    3    5
  64. //Sidorov S.S.         4   5    5    4    5    4
  65. //Durov D.D.          20   4    3    4    3    4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement