Code does not return values

The objective is to write a code using class and constructor as student with 4 data members: Name, id, Age and Address. The issue is my code does not return the values and there are no error codes. How can I get the student detaisl to output? thanks

Here is my code:


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
#include <iostream>
using namespace std;

class student {
public:
    string student_name;
    string student_id;
    string student_age;
    string student_address;
    
    
    student(string student_name, string student_id, string student_age, string student_address ) {
        student_name = student_name;
        student_id = student_id;
        student_age = student_age;
        student_address = student_address;
        
    }
  
    void PrintInfo() {
        cout  << "Student Information" << endl;
        cout  << "Student Name: "<< student_name << endl;
        cout  << "Student ID: "<< student_id << endl;
        cout  << "Student Age: "<< student_age << endl;
        cout  << "Student Address: "<< student_address << endl; 
        cout  << "" << endl;
    }
    
};

int main()

{

    student student1("Student 01", "ID001", "Age01", "Address01");
    student student2("Student 02", "ID002", "Age02", "Address02");
    student student3("Student 03", "ID003", "Age03", "Address03");
 
    student1.PrintInfo();
    student2.PrintInfo();
    student3.PrintInfo();

}
Last edited on
Either change your constructor to:
1
2
3
4
5
6
    student(string student_name, string student_id, string student_age, string student_address ) :
        student_name( student_name ),
        student_id( student_id ), 
        student_age( student_age ),
        student_address( student_address )
    {}


or use different names for its arguments.
@lastchance , its giving error messages with that s uggestion and changing argument names is giving same issue, no output
Well, this is your code with the changed constructor (and also #include<string>):

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
#include <iostream>
#include <string>
using namespace std;

class student {
public:
    string student_name;
    string student_id;
    string student_age;
    string student_address;
    
    student(string student_name, string student_id, string student_age, string student_address ) :
        student_name( student_name ),
        student_id( student_id ), 
        student_age( student_age ),
        student_address( student_address )
    {}
  
    void PrintInfo() {
        cout  << "Student Information" << endl;
        cout  << "Student Name: "<< student_name << endl;
        cout  << "Student ID: "<< student_id << endl;
        cout  << "Student Age: "<< student_age << endl;
        cout  << "Student Address: "<< student_address << endl; 
        cout  << "" << endl;
        return;
    }
    
};

int main()

{

    student student1("Student 01", "ID001", "Age01", "Address01");
    student student2("Student 02", "ID002", "Age02", "Address02");
    student student3("Student 03", "ID003", "Age03", "Address03");
 
    student1.PrintInfo();
    student2.PrintInfo();
    student3.PrintInfo();

}


It gives the following
Student Information
Student Name: Student 01
Student ID: ID001
Student Age: Age01
Student Address: Address01

Student Information
Student Name: Student 02
Student ID: ID002
Student Age: Age02
Student Address: Address02

Student Information
Student Name: Student 03
Student ID: ID003
Student Age: Age03
Student Address: Address03



its giving error messages

That is not helpful.
Thanks, I mistakenly entered ; instead of :

Its not giving Error messages now.
Topic archived. No new replies allowed.