How i can call function in another source 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
27
28
29
30
31
32
33
34
35
36
//Grades.h
#ifndef GRADES_H
#define GRADES_H
#include <iostream>
using namespace std;

class Grades{

public :

	int grades; 
	int studentNo [5];
	int exams [2];
	int total ;


void getGrades()
{

    for (int i=0;i<5;i++)
{
	cout<<"student number"<<i<<endl;
	
	for(int j=0;j<2;j++)
	{
	cout<<"exam number"<<j<<endl;
	cin>>exams[j];
	total+=exams[j];
	}
	
  }

 }

};
#endif 



just i want the total here
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//GradesSum.h
#ifndef GRADESSUM_H
#define GRADESSUM_H
#include <iostream>
#include "Grades.h"
using namespace std ;

class GradesSum : public Grades
{
public :
	float sum;

	void getGradesSum()

	{
		sum = 0;
		sum +=total;
	    cout << "The Sum Of Grades is :" << sum << endl;
	}
	
};
#endif 
Last edited on
I don't really understand your problem. Would you please describe it a little more detailed, please?

But nevertheless here are some tipps:

Grades::total, GradesSum::sum: These attributes may and one of them will be used uninitialized, so their contents may be undefined. Use a constructor to do initialization (see Tutorial on Cplusplus.com for details).

Header files are usually meant for specification, mainly classes, only. Better put your implementation into separate source files. Use f.e. Grades.cpp and GradesSum.cpp.
Topic archived. No new replies allowed.