how to store test scores?

hey guys, this is what i have so far, and im having trouble finding a way to store 5 test scores for each student that has been entered.
for example: enter name: chaotic
enter id number: 12312312
enter 5 test scores :
Enter test score 1:
Enter test score 2:
Enter test score 3 etc.......
heres me code so far

#include <iostream>
#include <string>
#include <iomanip>
#include <cstdlib>
using namespace std;

struct nameGPA
{
string name;
int idNUM;
int test[5];
double average;
char gpa;
};

void getData(nameGPA *&, int);


int main()
{

nameGPA *roster;
int num;

cout << "how many students?" << endl;
cin >> num;

getData(roster, num);



system("pause");
return 0;


}

void getData(nameGPA *&c, int number)
{
c = new nameGPA[number];

int i = 0;
for (i = 0; i < number; i++)
{
cout << "Enter info for student" << (i + 1) << " here" << endl;
cout << endl;

cout <<"Student name: " << endl;
cin >> c[i].name;
cout << "what is the students id number?" << endl;
cin >> c[i].idNUM;

}


}



Use std::vector<> http://www.mochima.com/tutorials/vectors.html

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <vector> // http://www.mochima.com/tutorials/vectors.html
#include <string>

struct student
{
    std::string name;
    int id;
    int test_scores[5];
    double average = 0.0 ; // http://www.stroustrup.com/C++11FAQ.html#member-init
    char gpa = ' ' ;
};

std::vector<student> getData( int num );

int main()
{
    int num;
    std::cout << "how many students? " ;
    std::cin >> num;

    std::vector<student> roster = getData(num);

    for( student s : roster ) // http://www.stroustrup.com/C++11FAQ.html#for
    {
        std::cout << s.name << ' ' << s.id << " scores: " ;
        for( int v : s.test_scores ) std::cout << v << ' ' ;
        std::cout << '\n' ;
    }
}

std::vector<student> getData( int num )
{
    std::vector<student> roster ;

    student s ;
    for( int i = 0; i < num; ++i )
    {
        std::cout << "Enter info for student" << (i + 1) << " here\n" ;

        std::cout <<"Student name (without spaces): " ;
        std::cin >> s.name;

        std::cout << "what is the students id number? " ;
        std::cin >> s.id;

        const int NTESTS =  sizeof(s.test_scores) / sizeof(s.test_scores[0]) ;
        std::cout << "enter " << NTESTS << " test_scores scores: " ;
        // http://www.stroustrup.com/C++11FAQ.html#for
        for( int& score : s.test_scores ) std::cin >> score ;

        roster.push_back(s) ;
    }

    return roster ;
}
Topic archived. No new replies allowed.