Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <iomanip>
- using namespace std;
- int inputData(string*&, double**&);
- void displayData(string*, double**, int);
- void cleanHeap(string*, double**, int);
- int main()
- {
- string* name = nullptr;
- double** grades = nullptr;
- int total = inputData(name, grades);
- cout << "You have " << total << " students in the system." << endl;
- displayData(name, grades, total);
- cleanHeap(name, grades, total);
- cout << name[0];
- cout << grades[0][1];
- }
- int inputData(string *&name, double **&grades)
- {
- int numinput = 0, x = 0, numtests, numstudents;
- cout << "How many students do you have in the system? " << endl;
- cin >> numstudents;
- grades = new double*[numstudents];
- name = new string [numstudents];
- for (int i = 0; i < numstudents; i++ )
- {
- cout << "Enter the student's name: ";
- cin.get();
- getline(cin , name[i]);
- numinput++;
- cout << "Enter how many tests " << name[i] << " took: ";
- cin >> numtests;
- grades[i] = new double[numtests+1];
- cout << grades[i] << "**" << endl;
- grades[i][x] = numtests;
- for (int x = 1; x <= numtests; x++)
- {
- cout << "Enter grade # " << x << ": ";
- cin >> grades[i][x];
- }
- cout << endl;
- }
- return numinput;
- }
- void displayData(string* name, double** grades, int total)
- {
- for (int x = 0; x < total; x++)
- {
- cout << "Name of student #" << (x + 1) << ": " << name[x] <<endl;
- cout << "Grades for student #" << (x + 1) << ": ";
- for (int y = 1; y <= grades[x][0]; y++)
- {
- cout << grades[x][y] << " ";
- }
- cout << endl;
- }
- }
- void cleanHeap(string* name, double** grades, int total)
- {
- delete [] name;
- for (int i = 0; i<total; i++)
- {
- delete [] grades[i];
- }
- delete [] grades;
- name = nullptr;
- grades=nullptr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement