using arrays in classes

I did this with strings, as I couldnt figure out how to do it with a char
array. I know strings can be beneficial, but my goal is to use strings, as
I've been unable to find how to do it with arrays with other exercises...
Please help!!


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
57
58
/*
This program asks the user for a student's name and grades, then prints the name along with the total
grade.
*/

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

class Student
{
	string name;				//name of the student
	string yourName;
	int marks1 = 0, marks2 = 0;	//Each of the student's marks(grades), zero is default
	int total;					//total of the student's marks
public:
	string getName(string name);					//receives the name from the user
	int calc(int marks1, int marks2);				//receives and adds together the student's marks (zero is default)
	void disp(string yourName, int totalGrade);		//displays the name and grade of the student
	Student()
	{
		yourName = getName(name);
		total = calc(marks1, marks2);
		disp(yourName, total);
	}
};

string Student::getName(string name)
{
	cout << "Enter your name: ";
	getline(cin, name);
	return name;
}

int Student::calc(int grade1, int grade2)
{
	cout << "Enter first grade: ";
	cin >> grade1;
	cout << "Enter second grade: ";
	cin >> grade2;
	int total = grade1 + grade2;
	return total;
}

void Student::disp(string yourName, int totalGrade)
{
	cout << endl;
	cout << "Name: " << yourName << endl
		<< "Total Grade: " << totalGrade << endl;
}

int main()
{
	Student student1;		//with default constructors, dont use ()

	system("pause");
	return 0;
}
Topic archived. No new replies allowed.