Parameter errors and such

I am getting errors for "Student student1(name, grades[3]);" and everywhere I have "student2" attached. It is mostly stating "cannot convert parameter 2 from 'double' to double[]'. Not sure where my errors are, I keep looking over everything and it's probably right in front of me.

Main:
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
  #include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
	double grades[3];
	string name;

	cout << "Please enter a student name: ";
	cin >> name;
	cout << "Please enter grade #1: ";
	cin >> grades[0];
	cout << "Please enter grade #2: ";
	cin >> grades[1];
	cout << "Please enter grade #3: ";
	cin >> grades[2];
	cout << endl << endl;

	Student student1(name, grades[3]);

	

	cout << "First student:" << endl << student1.GetName() << endl;
	cout << "Grades: " << student1.GetGrade1() << " " << student1.GetGrade2() 
		 << " " << student1.GetGrade3();

	cout << endl;
	
	Student student2 (student1);
	cout << "Copying student and changing grades... " << endl << endl;
	cout << "Copied student: " << endl;
	cout << student2.GetName() << endl;

	student2.SetGrades(student2.GetGrade1() + 10);
	student2.SetGrades(student2.GetGrade2() + 10);
	student2.SetGrades(student2.GetGrade3() + 10);
	cout << "Grades: " << student2.GetGrade1() << " " 
		 << student2.GetGrade2() << " " << student2.GetGrade3();
	cout << endl;

	cout << "First student:" << endl << student1.GetName() << endl;
	cout << "Grades: " << student1.GetGrade1() << " " << student1.GetGrade2() 
		 << " " << student1.GetGrade3();

	system("PAUSE");
	return 0;
}



Student.cpp
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
#include "Student.h"
#include <string>
using namespace std;


Student::Student(string name, double grades[3])
{
	_name = name;
	_grades[0] = grades[0];
	_grades[1] = grades[1];
	_grades[2] = grades[2];
	
}

string Student:: GetName()
{
	return _name;
}

double Student:: GetGrade1()
{
	return _grades[0];
}

double Student:: GetGrade2()
{
	return _grades[1];
}

double Student:: GetGrade3()
{
	return _grades[2];
}

void Student::SetGrades( double grades[])
{
	_grades[0] = grades[0];
	_grades[1] = grades[1];
	_grades[2] = grades[2];
}


Student.h file:

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
#ifndef STUDENT_H
#define STUDENT_H

#include <string>
using namespace std;

class Student
{
private:
	string _name;
	double _grades[3];

public:
	Student(string, double[]);
	~Student();
	Student(const Student&);
	string GetName();

	double GetGrade1();
	double GetGrade2();
	double GetGrade3();
	void SetGrades(double[]);
	
};

#endif 


Here is the assignment goal if anyone is interested:

1. Objective: to demonstrate your knowledge of creating a class and its copy
constructor. Create a class named Student which stores the student's name and grades in
a double array which can store 3 grades. Create a method called SetGrades which takes
three doubles and alters the grades. Create a method scalled GetGrade1, GetGrade2 and
GetGrade3.
Create one Student object and set the grades, then print out the grades.
Create another Student object based on the first Student object by using the copy
constructor. Alter the grades of the second Student object and print out the grades. Finally,
print out the original grades.
Last edited on
Student student1(name, grades[3]);
here you are trying to pass a double to the student constructor which expects a double[]

student2.SetGrades(student2.GetGrade1() + 10);
same problem you are passing a double to a method that expects a double[]

also your destructor and copy constructor are undefined.
I am unsure of what you mean exactly. We just started the process of creating our own classes and such.
Nevermind I figured it out! Thank you!
Topic archived. No new replies allowed.