#include <conio.h>
#include <iostream.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
class student
{
char name[30];
float marks[3];
public:
float total(void);
void getdata(void);
void showdata(void);
};
student akshit[5];
void main()
{
clrscr();
for(int i=0; i<3; i++)
{
akshit.getdata();
akshit.showdata();
}
float total();
getch();
}
void student :: getdata(void)
{
for(int i=0; i<3; i++)
{
cout<<"Enter student's name - ";
gets(akshit.name);
for(int j=0; j<3; j++)
{
cout<<endl<<"Enter Marks in subject "<<j+1<<" - ";
cin>>akshit.marks[j];
}
}
}
void student :: showdata(void)
{
for(int i=0; i<3; i++)
{
cout<<endl<<endl<<"Name of student "<<akshit.name;
for(int j=0; j<3; j++)
cout<<endl<<"Marks - "<<akshit.marks[j]<<endl;
}
}
float student :: total(void)
{
float s=0;
for(int i=0; i<3; i++)
{
for(int j=0; j<3; j++)
s+=akshit.marks[j];
}
return (s);
}
Just want it to run for 3 students for marks in 3 subjects ...
Problem is that I've got a for loop in main() as well as in the function ... so.... how do i remove one ?(Tried removing as it is but then I need to have something for "X" --- akshit.[X].name ...
PS: Final exam tomorrow
... So RELPPP !!!
#include <iostream.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
class student
{
char name[30];
float marks[3];
public:
float total(void);
void getdata(void);
void showdata(void);
};
student akshit[5];
void main()
{
clrscr();
for(int i=0; i<3; i++)
{
akshit.getdata();
akshit.showdata();
}
float total();
getch();
}
void student :: getdata(void)
{
for(int i=0; i<3; i++)
{
cout<<"Enter student's name - ";
gets(akshit.name);
for(int j=0; j<3; j++)
{
cout<<endl<<"Enter Marks in subject "<<j+1<<" - ";
cin>>akshit.marks[j];
}
}
}
void student :: showdata(void)
{
for(int i=0; i<3; i++)
{
cout<<endl<<endl<<"Name of student "<<akshit.name;
for(int j=0; j<3; j++)
cout<<endl<<"Marks - "<<akshit.marks[j]<<endl;
}
}
float student :: total(void)
{
float s=0;
for(int i=0; i<3; i++)
{
for(int j=0; j<3; j++)
s+=akshit.marks[j];
}
return (s);
}
Just want it to run for 3 students for marks in 3 subjects ...
Problem is that I've got a for loop in main() as well as in the function ... so.... how do i remove one ?(Tried removing as it is but then I need to have something for "X" --- akshit.[X].name ...
PS: Final exam tomorrow
