13. Create a C++ class for student having following members. – Rollno – Name – Number of subjects – Marks of each subject (Number of subjects varies for each student) Write a parameterized constructor which initializes rollno, name & Number of subjects and creates the array of marks dynamically. Display the details of all students with percentage and class obtained


#include<iostream.h>
#include<conio.h>
#include<string.h>
class student
{
int rno,ns,s;
float per;
char name[20];
int *m;
public:
student(int no,char *nm,int nos)
{
rno=no;
strcpy(name,nm);
ns=nos;
m=new int[ns];
}
void get();
void cal();
void disp();
};
void student::get()
{
for(int i=0;i<ns;i++)
{
cout<<“\n\nEnter the subject “<<i+1<<” Marks” ;
cin>>m[i];
}
}
void student::cal()
{
s=0;
for(int i=0;i<ns;i++)
{
s=s+m[i];
}
per=s/ns;
}
void student::disp()
{
cal();
cout<<“\n\nRoll no: “<<rno;
cout<<“\n\nName: “<<name;
for(int i=0;i<ns;i++)
{
cout<<“\n\nMarks of “<<i+1<<” Subject: “<<m[i];
}
cout<<“\n\npercentage: “<<per;
}

void main()
{
int no,nos;
char nm[20];
clrscr();
cout<<“\nEnter roll no name no of subject:\n”;
cin>>no>>nm>>nos;
student st(no,nm,nos);
st.get();
st.disp();
getch();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s