Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstddef>
  3. #include <cstdlib>
  4. #include <fstream>
  5. #include <string>
  6. #include <vector>
  7. #include <algorithm>
  8. using namespace std;
  9.  
  10. struct Date
  11. {
  12. int day, month, year;
  13. };
  14.  
  15.  
  16. struct Grade
  17. {
  18. int s1, s2, s3, s4, s5, s6;
  19. };
  20.  
  21. struct Student
  22. {
  23. bool free;
  24. long studentID;
  25. string fname;
  26. string sname;
  27. Date DOB, DOE, DOG;
  28. Grade semester1, semester2;
  29. };
  30.  
  31. void initialise_database(vector<Student>, int size); // initialize each free variable to free
  32.  
  33. int main(int argc, char** argv)
  34. {
  35. fstream fin;
  36. char choice_readfile;
  37. int rowcount;
  38.  
  39. int size;
  40. cout << "Enter number of student:n";
  41. cin >> size;
  42.  
  43. vector<Student> BENG;
  44.  
  45.  
  46. do //verify choice to read from file is Y,y or N,n
  47. {
  48. cout << "Do you wish to read from file (Y/N)? (file name must be named students.txt)" << endl; //choice for user to read from external file
  49. cin >> choice_readfile;
  50. while(cin.fail())
  51. {
  52. cin.clear();
  53. cin.ignore(80,'n');
  54. cout << "Please Re-Enter choice" << endl;
  55. cin >> choice_readfile; // choice to read from file
  56. }
  57. }
  58. while(choice_readfile != 'Y' && choice_readfile != 'y' && choice_readfile != 'N' && choice_readfile != 'n');
  59.  
  60. if(choice_readfile == 'Y' || choice_readfile == 'y')
  61. {
  62. fin.open("students.txt", ios::in|ios::out); //opens mygrades.txt
  63. if(fin.fail())
  64. {
  65. cout << "Error occured while opening students.txt" << endl;
  66. exit(1);
  67. }
  68. fin.clear();
  69. fin.seekg(0);
  70.  
  71. string line;
  72. while( getline(fin, line) ) //counts the rows in the external file
  73. {
  74. rowcount++;
  75. }
  76.  
  77. cout << "Number of rows in file is " << rowcount << endl;
  78. cout << size << " " << rowcount << endl;
  79. }
  80.  
  81. size += rowcount;
  82. int i=0;
  83. initialise_database(BENG, size);
  84. return 0;
  85. }
  86.  
  87. void initialise_database(vector<Student> BENG, int size)
  88. {
  89. for(int i=0;i<size;i++)
  90. {
  91. BENG[i].free = false;
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement