help plz

MY QUESTION:


Line# 8: could not convert '0' from int to std::ifstream;

Line# 24: No matching function for call to TA::set;


Can anyone please see what i did wrong here?
Thank you in advance <3


---------------------------------------------------------
THE CODE:

The 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
#include "TA.h"

int main()
{
    ifstream inFile;
    inFile.open("courses.txt");

	TA someTA;
	string TAName;
	int nCourses, nHours;
	string sID, dept;
	float pRate;

	inFile >> nCourses >> sID;
	getline(inFile, TAName);

	cout << "Enter the department name: ";
	cin >> dept;
	cout << "Enter the number of hours: ";
	cin >> nHours;
	cout << "Enter the rating: ";
	cin >> pRate;

	someTA.set(inFile, sID, TAName, nCourses, dept, nHours, pRate);
	someTA.print();

	return 0;
}


The student header:-

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

#include <iostream>
#include <cstring>
#include <cassert>
#include <fstream>
#include <cmath>

using namespace std;

struct course
{
    string code, title;
    int credit, mark ;
};
class student
{
    private:

    string ID, name;
    float GPA;
    int numberOfCourses ;
    course *p;

    public:

    void set(ifstream&, string, string, int);
    void calculateGPA( );
    float getGPA( )const;
    int getNumberOfCourses( )const;
    void print( )const;

    ~student();
    student(ifstream&, string = "", string = "", int = 0);
    student(const student&);
};

#endif // STUDENT_H_INCLUDED
[code]

The TA header:-

[code]#ifndef TA_H_INCLUDED
#define TA_H_INCLUDED

#include "Student.h"

class TA: public student
{
    private:

    string department;
    float rating ,salary;
    int numberOfHours;

    public:
    void calculateSalary();
    void set(ifstream&, string, string, int,string, int, float);
    float getSalary()const;
    void print()const;

    TA(ifstream&, string = "", string = "", int = 0,string = "", int = 0, float = 0.0);
};

#endif // TA_H_INCLUDED 


The Student implementation:-

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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "Student.h"

void student::set(ifstream& inFile, string a, string b, int x)
{
    ID = a;
    name = b;
    numberOfCourses = x;
    delete [] p;

    p = new int [numberOfCourses];
    assert(p != 0);

    for(i = 0; i < numberOfCourses; i++)
    {
        inFile >> p[i].code >> p[i].title
        >> p[i].credit >> p[i].mark;

        // I passed every value taken from the courses.txt file and assigned it to the right variable using a loop.
    }

    calculateGPA();
}
void student::calculateGPA()// This function is used to calculate the GPA.
{
    int k = 0;
    int j = 0;
    double totHours = 0;
    double totMark = 0;
// The following code is to sum up all the hours.
        while(k < numberOfCourses)
        {
            totHours = totHours + p[k].credit;
            k+=1;
        }
// The following code is to check each mark and assign the mark to A,B+,B,C+,C,D+,D, and F.
        while(j < numberOfCourses)
        {
            if(p[j].mark > 90)//A
        {
            p[j].mark = 4.00;
            totMark =  totMark + (p[j].mark * p[j].credit);
        }
            else if(p[j].mark > 85)//B+
            {
                p[j].mark = 3.33;
                totMark =  totMark + (p[j].mark * p[j].credit);
            }
                else if(p[j].mark > 80)//B
                {
                    p[j].mark = 3.00;
                    totMark =  totMark + (p[j].mark * p[j].credit);
                }
                    else if(p[j].mark > 75)//C+
                    {
                        p[j].mark = 2.30;
                        totMark =  totMark + (p[j].mark * p[j].credit);
                    }
                        else if(p[j].mark > 70)//C
                        {
                            p[j].mark = 2.00;
                            totMark =  totMark + (p[j].mark * p[j].credit);
                        }
                            else if(p[j].mark > 65)//D+
                            {
                                p[j].mark = 1.30;
                                totMark =  totMark + (p[j].mark * p[j].credit);
                            }
                                else if(p[j].mark > 60)//D
                                {
                                    p[j].mark = 1.00;
                                    totMark =  totMark + (p[j].mark * p[j].credit);
                                }
                                    else//F
                                        {
                                            p[j].mark = 0.00;
                                            totMark =  totMark + (p[j].mark * p[j].credit);
                                        }
                                    j+=1;
            }
    GPA = totMark/totHours;
// This is the formula to calculate the GPA.
}
float student::getGPA()const // This is the function that returns the value of the GPA.
{
    return GPA;
}

int student::getNumberOfCourses( )const;
{
    return getNumberOfCourses;
}

void student::print()const // This function prints out the ID, student name, and the students GPA.
{
    cout<<ID<<" "<<name<<" "<<"has GPA = "<<GPA << "\n";
}
student::student(ifstream& inFile, string a, string b, int x)
{
    ID = a;
    name = b;
    numberOfCourses = x;

    p = new int [numberOfCourses];
    assert(p != 0);

    for(i = 0; i < numberOfCourses; i++)
    {
        p[i] = 0;
        // I passed every value taken from the courses.txt file and assigned it to the right variable using a loop.
    }
}

student::~student()
{
	delete [] p;
	p = NULL;
}

student::student(const student &otherObject)
{
	numberOfCourses = otherObject.numberOfCourses;

	p = new int[numberOfCourses];
	assert( p != NULL );

	for(int i=0; i<numberOfCourses; i++)
		p[i] = otherObject.p[i];
}
]


And the TA implementation:-

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
#include "TA.h"

void TA::set(ifstream w, string a, string b, int x,string c, int y, float z)
{
    student::set(w,a,b,x);

    department = c;
    numberOfHours = y;
    rating = z;

    calculateSalary();
}
void calculateSalary()
{
    float extraHours;

    if(numberOfHours <= 40)
    {
        salary = rating * numberOfHours;
    }

    else
        {
            extraHours = numberOfHours - 40;
            extraHours = extraHours * 1.5;
            extraHours = extraHours + 40;

            salary = extraHours * rating;
        }
}

float TA::getSalary() // This function calculates the salary.
{
   return salary;
}

void TA::print() // This will print out the department,number of hours, rating, and salary.
{
    cout<< "Working in "<<department<< " department for "<<numberOfHours<< " hours"<<"\n";
    cout<< "Rating is "<<rating<<" per hour and salary is: "<< salary<<"\n";
}
TA::TA(ifstream inFile, string a, string b, int x,string c, int y, float z)
{
    student::set(inFile,a,b,x);

    department = c;
    numberOfHours = y;
    rating = z;

}

Last edited on
ifstream = 0 You can't convert an int to std::ifstream
hmmm what should i do then?
What are you trying to achieve by writing ifstream = 0? It's not clear what it is you want to do.
thats the way u make a parametrized constructor right??

like how i did with int = 0 ans string = " "
Does std::ifstream have a constructor that takes a single integer value?
no im supposed to read 4 lines of different values.....
wait i solved the problem with line 24 but plz can anyone tell me whats the prob with line 8?
You changed the code. What error are you getting?
At line number #8 in the main i get this:

Error: no matching function for to call to 'TA::TA()'.

I have absolutely why this code is giving me an error......i included the student header in TA and included the TA header in main but y do i get this???

plz help and thanx in advance
As the error message says, your TA class has no default constructor. You've defined a constructor that takes 7 arguments.

If you define another constructor, the compiler won't automatically generate default one. If you also need a default constructor, you must manually declare and define it too.

Edit: Note that at line 8 of main.cpp, you're attempting to use the default constructor, because you're instantiating a TA object with no parameters.
Last edited on
but i made a default parametrised constructor why must i make another default constructor?
Last edited on
Nope. The first parameter doesn't have a default value.
the ifstream?

buth thanx allot i made a default parameter and the thing worked :D
Topic archived. No new replies allowed.