Hello guys. I'm not very good at at programing but i need to do one program which should do this:
Write a program with objects which stores student marks of exam. All the information is read. It must be realized:
a. I enter all students marks;
b. and see whose marks and subject screen ;
c. count evry student average mark
But where is a problem in this program. when i put all marks and subjects for 2 maybe more students the marks are being showed in screen only from last student. so all students have the same marks like the last one.
and counting average mark also it dont work :(. Sorry for my english i'm from lithuania.
#include <cstdlib>
#include <iostream>
#include <fstream>
using namespace std;
class student
{
public:
int subjectmark,sk,i,sum,mark[100];
int average[100];
int amount;
char name[100];
char surname[100];
char subject[100];
void read();
void to_screen();
void averagek();
};
void student::read ()
{
{
cout << "Please enter students number:" << endl;
cin >> sk;
cout << "Please enter students subjects number:" << endl;
cin >> amount;
if (sk <= 0)
{
cout << "Bad number. program closes." << endl;
cin >> sk;
system("PAUSE");
{exit (1);};
}
cout << endl;
cout << "Enter names,surnames ect." << endl << endl;
for (int i=0; i<sk; i++)
{
cout<<"Enter student name and surname:"<<endl;
cin>>name;
cin>>surname;
for (int j=0; j<amount; j++)
{
cout<<"Enter subject name "<<endl;
cin>>subject;
cout<<"Enter subject mark "<<endl;
cin>>mark[100];
}}}}
void student::to_screen ()
{
cout << "-----------------------------------------------------------------------" << endl;
cout << "Name \t\t | surname\t | subject\t\t| Mark.|" << endl;
cout << "-----------------------------------------------------------------------" << endl;
for(int i=0; i<sk; i++)
{
for (int j=0; j<amount; j++)
{
cout << name << "\t\t | " << surname << "\t | " << subject << "\t\t | " << mark[100] << " \t| " << endl;
cout << "------------------------------------------------------------------------" << endl;
cout << endl;
cout << "Average mark for student : " << average[100] << endl << endl;
}}}
void student::averagek()
{
sum=0;
average[100]=0;
for (int j=0; j<amount; j++)
sum+=mark[100];
average[100] = sum/amount;
}
int main()
{
student z;
z.read();
z.to_screen();
z.averagek();
system("PAUSE");
return 0;
}