Having problems writing constructors

I am trying to rewrite the constructors in this code. For this problem it says the written program asks for a student name and a student id. The main program then creates a student object with the name and id entered into the code. Rewrite the constructor the same was as in the previous coding problem.However I wonder if I have written them as classes. Whenever I run this code it keeps on getting errors. How would I fix this code? This is what I have so far.
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
  #pragma once
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

class Student
{
private:
	string name;
	int id;

public:
	Student(string name, int id);
	string getName();
	int getId();
	//Add setName function here

	~Student();
class Student
{
private:
	string name;
	int id;
	// Add address variable

public:
	Student(string StudentName, int StudentId);
	string toString();

	~Student();
};
    class Student
{
private:
	string name;
	int id;
	// Add address variable

public:
	Student(string StudentName, int StudentId);
	string toString();

	~Student();
};
    {
};

//Write setName function here

Student::Student(string studentName, int studentId)
{
	name = studentName;
    id = studentId;
     
}

string Student::getName()
{
   name = getName;
    id = studentId;
     	
return name;
}

int Student::getId()
{
	return id;
}

Student::~Student()
{
}

int main()
{
	string studentName;
	cin >> studentName;

	Student student("Old Name", 12345);

	student.setName(studentName);

	if (studentName == student.getName())
	{
		cout << "Correct name" << endl;
	}
	else
	{
		cout << "Name is incorrect" << endl;
	}

	if (12345 == student.getId())
	{
		cout << "Correct Id" << endl;
	}
	else
	{
		cout << "Id is incorrect" << endl;
	}

	return 0;
}
Last edited on
1
2
line 21: error: 'Student::Student' has the same name as the class in which it is declared|
line 34: error: 'Student::Student' has the same name as the class in which it is declared|


and a lot of the subsequent errors stem from the above ones, try compiling your program and addressing the obvious errors first
Topic archived. No new replies allowed.