fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4. #include <cstdlib>
  5. using namespace std;
  6.  
  7. struct PERSON
  8. {
  9. string name;
  10. int age;
  11. float gpa;
  12. };
  13. PERSON *p;
  14.  
  15. int main()
  16. {
  17. int count;
  18. cout << "Please enter the number of records you wish to enter: ";
  19. cin >> count;
  20.  
  21. p = new PERSON[count];
  22.  
  23. for (int i = 0; i < count; i++)
  24. {
  25. cout << "Enter name, age, and gpa: ";
  26.  
  27. cin >> p[i].name;
  28. cin >> p[i].age;
  29. cin >> p[i].gpa;
  30.  
  31. cout << endl;
  32. }cout << endl;
  33.  
  34. cout << "This is the content of array p: " << endl;
  35. cout << right << setw(8) << "NAME" << setw(7) << "AGE" << setw(7) << "GPA" << endl;
  36. cout << "--------------------------" << endl;
  37.  
  38. for (int i = 0; i < count; i++)
  39. {
  40. cout << p[i].name << " " << p[i].age << " " << p[i].gpa << endl;
  41. }
  42. delete[] p;
  43. return 0;
  44. }
Success #stdin #stdout 0s 3280KB
stdin
3
Robert 21 2.1
Aardvark 22 2.2
Beta 23 2.3
stdout
Please enter the number of records you wish to enter: Enter name, age, and gpa: 
Enter name, age, and gpa: 
Enter name, age, and gpa: 

This is the content of array p: 
    NAME    AGE    GPA
--------------------------
Robert 21 2.1
Aardvark 22 2.2
Beta 23 2.3