produce a program to store the names and marks of students

content has been deleted
Last edited on
A simple implementation:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <string>
using namespace std;

int main()
{
   int numstudents;
   cout << "Enter the class size: ";
   cin >> numstudents;
   string first, last;
   string names[numstudents];
   int marks[numstudents];

   for (int i = 0; i < numstudents; i++) {
      cout << "Enter a student's name: ";
      cin >> first >> last;
      names[i] = string(first) + string(" ") + string(last);
      cout << "Enter " << names[i] << "'s mark: ";
      cin >> marks[i];
   }

   cout << "\n\nStudents:" << endl;
   for (int j = 0; j < numstudents; j++) {
      cout << "  Name: " << names[j] << endl;
      cout << "    Mark: " << marks[j] << endl;
   }

   return 0;
}


I know this isn't necessarily the best way to do this, as you can use getline() or cin.getline(), but I haven't yet figured those out completely. I don't want you to just copy this though. If you don't understand or have any questions, please say so!
Dream on trojansdestroy. Posters that just cut and paste the problem, also just cut and paste the (your) answer. If you want to help, help them work through it. But don't post complete solutions. ;-)
Topic archived. No new replies allowed.