fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. using namespace std;
  5. class Record
  6. {
  7. private:
  8. string name;
  9. string rollNo;
  10. public:
  11. string getName();
  12. string getRollNo();
  13. void putData();
  14. void setData();
  15. };
  16. void Record::setData()
  17. {
  18. cout << endl << "Enter Name:";
  19. cin.ignore();
  20. getline(cin,name,'$');
  21. cout << endl << "Enter Roll No:";
  22. cin.ignore();
  23. getline(cin,rollNo,'$');
  24. }
  25. void Record::putData()
  26. {
  27. cout << endl << "Name:"<<getName();;
  28. cout << endl << "Roll No:"<<getRollNo();
  29. }
  30. string Record::getName()
  31. {
  32. return name;
  33. }
  34. string Record::getRollNo()
  35. {
  36. return rollNo;
  37. }
  38. int count=0;
  39. int main()
  40. {
  41. Record *pRecord[999];
  42. fstream file;
  43. file.open("c:\\record.txt");
  44. char choice;
  45. bool breakLoop = false;
  46. int i=0;
  47. do
  48. {
  49. cout << endl << "\t\tSchool Database";
  50. cout << endl << "1. Add Record";
  51. cout << endl << "2. Show Record";
  52. cout << endl << "3. Exit";
  53. cin >> choice;
  54. string str;
  55. switch(choice)
  56. {
  57. case '1':
  58. pRecord[count]= new Record;
  59. pRecord[count] -> setData();
  60. file << pRecord[count]->getName();
  61. file << "\n";
  62. file << pRecord[count]->getRollNo();
  63. count++;
  64.  
  65.  
  66. break;
  67.  
  68. case '2':
  69. if(count == 0)
  70. {
  71. cout << "Sorry no record available";
  72. break;
  73. }
  74. //i initialized outside now
  75. do
  76. {
  77. getline(file,str);
  78. cout << str;
  79. }while(file);
  80. break;
  81. case '3':
  82. breakLoop = true;
  83. break;
  84. default:
  85. breakLoop = true;
  86. break;
  87. }
  88. }while(breakLoop == false);
  89. file.close();
  90. return 0;
  91. }
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:46: warning: unused variable ‘i’
stdout
		School Database
1. Add Record
2. Show Record
3. Exit