Problems on program

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
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
class Student
{
public:
    int iD;
    string firstName;
    string lastName;
    int examGrade;
    bool isdeleted;
    Student();
    void getter(int, int);
    void setter();
};
int main()
{
	Student Info;
	Student *records;
    int people;
	int count = 0;
	int option = 0;
	cout << "How many people info do you want? ";
	cin >> people;
	records = new Student[people];
	fstream stream;
	stream.open("Records.txt", ios::in);
	if(!stream.open())
	{
		system("pause");
		exit(1);
	}
	stream << people;
	for(int i = 0; i < people; i++)
	{
		stream >> Info.iD >> Info.firstName >> Info.lastName >> Info.examGrade;
		records[i] = Student(Info.iD, Info.firstName, Info.lastName, Info.examGrade);
		cout << endl;

		if(i == people-1)
		{
			cout << "Please enter the ID of the student to be deleted. " << endl;		
			cout << "To exit, please type -1. " << endl;
			cin >> option;
				if(option == -1)
				{
					exit(1);
					system("pause");
				}
				if(option != -1)
				{
					for(int j = 0; j < people; j++)
					{
						if(option == records[j].iD)
						{
							count++;
							records[j].isdeleted = true;
						}
					}
				}
		}

	}
	stream.close();
	stream.open("Records.txt", ios:: out);
	stream << people-count << endl;
	for(int j = 0; j < people-count; j++)
	{
		if(records[j].isdeleted == true)
		{
			stream << records[j].iD << " " << records[j].firstName << " " << records[j].lastName << " " << records[j].examGrade; 
		}
	}

    system("pause");
    return 0;
}
Student::Student()
{
    
    
}


I'm getting errors "no overload function takes 4 arguments" anyone know how to fix it Thanks!
Last edited on
It is as it says: there is no constructor for class Student which takes 4 arguments.

You can add it to the class.
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
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;

class Student
{

public:
    int iD;
    string firstName;
    string lastName;
    int examGrade;
    bool isdeleted;
    Student();
    Student(int, string, string, int);
};
void main()
{
    Student Info;
    Student *records;
    int people;
    int count = 0;
    int option = 0;
    
    cout << "How many people info do you want? ";
    cin >> people;
    records = new Student[people];
    fstream file;
    file.open("Records.txt", ios::in);
  
    file << people;
    
    for(int i = 0; i < people; i++)
    {
        cout << "Please enter the student's id: ";
        cin >> Info.iD;
        cout << "Please enter the student's first name: ";
        cin >> Info.firstName;
        cout << "Please enter the student's last name: ";
        cin >> Info.lastName;
        cout << "Please enter the student's exam grade: ";
        cin >> Info.examGrade;
        records[i] = Student(Info.iD, Info.firstName, Info.lastName, Info.examGrade);
        cout << endl;
        file << Info.iD << Info.firstName << Info.lastName << Info.examGrade;
        if(i == people-1)
        {
            cout << "Please enter the ID of the student to be deleted. " << endl;
            cout << "To exit, please type -1. " << endl;
            cin >> option;
            
            if(option == -1)
            {
                exit(1);
                
            }
           
            if(option != -1)
            {
                for(int j = 0; j < people; j++)
                {
                  
                    if(option == records[j].iD)
                    {
                        count++;
                        records[j].isdeleted = true;
                    }
                }
            }
        }
        
    }
    file.close();
   
    file.open("Records.txt", ios:: out);
    file << people-count << endl;
    for(int j = 0; j < people-count; j++)
    {
        if(records[j].isdeleted == true)
        {
            
            file << records[j].iD << " " << records[j].firstName << " " << records[j].lastName << " " << records[j].examGrade;
        }
    }
    
    system("pause");
 
}
Student:: Student()
{}

Student::Student(int iD, string firstName, string lastName, int examGrade)
{
    int ID = 0, exam_Grade = 0;
    string first_Name, last_Name;
    iD = ID;
    firstName = first_Name;
    lastName = last_Name;
    examGrade = exam_Grade;
}


I fix that problem already but i'm trying to figure out why it doesn't print anything to the file "Records.txt" that i created. Do you know whats the problem?
Thanks again!
Last edited on
Your constructor does not do anything remotely helpful. It does not initialize anything in your class.


void main() — Illegal C++, main() shall return int.

records[i] = Student(Info.iD, Info.firstName, Info.lastName, Info.examGrade); Why not just write records[i] = Info;?
Topic archived. No new replies allowed.