Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. int inputData(string*&, double**&);
  8. void displayData(string*, double**, int);
  9. void cleanHeap(string*, double**, int);
  10.  
  11. int main()
  12. {
  13. string* name = nullptr;
  14. double** grades = nullptr;
  15. int total = inputData(name, grades);
  16. cout << "You have " << total << " students in the system." << endl;
  17. displayData(name, grades, total);
  18. cleanHeap(name, grades, total);
  19. cout << name[0];
  20. cout << grades[0][1];
  21. }
  22.  
  23. int inputData(string *&name, double **&grades)
  24. {
  25. int numinput = 0, x = 0, numtests, numstudents;
  26. cout << "How many students do you have in the system? " << endl;
  27. cin >> numstudents;
  28. grades = new double*[numstudents];
  29. name = new string [numstudents];
  30.  
  31. for (int i = 0; i < numstudents; i++ )
  32. {
  33. cout << "Enter the student's name: ";
  34. cin.get();
  35. getline(cin , name[i]);
  36. numinput++;
  37. cout << "Enter how many tests " << name[i] << " took: ";
  38. cin >> numtests;
  39. grades[i] = new double[numtests+1];
  40. cout << grades[i] << "**" << endl;
  41. grades[i][x] = numtests;
  42. for (int x = 1; x <= numtests; x++)
  43. {
  44. cout << "Enter grade # " << x << ": ";
  45. cin >> grades[i][x];
  46. }
  47. cout << endl;
  48. }
  49. return numinput;
  50. }
  51.  
  52. void displayData(string* name, double** grades, int total)
  53. {
  54. for (int x = 0; x < total; x++)
  55. {
  56. cout << "Name of student #" << (x + 1) << ": " << name[x] <<endl;
  57. cout << "Grades for student #" << (x + 1) << ": ";
  58. for (int y = 1; y <= grades[x][0]; y++)
  59. {
  60. cout << grades[x][y] << " ";
  61. }
  62. cout << endl;
  63. }
  64. }
  65.  
  66. void cleanHeap(string* name, double** grades, int total)
  67. {
  68. delete [] name;
  69. for (int i = 0; i<total; i++)
  70. {
  71. delete [] grades[i];
  72. }
  73. delete [] grades;
  74. name = nullptr;
  75. grades=nullptr;
  76.  
  77.  
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement