Saturday, 23 June 2012

create a c++ class for student object with the following attribute- rollno, name,number of subject. the number of subject varies for each student. write a parmeterised constructor which will initialise rollno, name, and number of subject and create the array for marks dynamically. write member function for accepting marks and display all student of marks

/*create a c++ class for student object with the following attribute- rollno,
name,number of subject. the number of subject varies for each student.
write a parmeterised constructor which will initialise rollno, name, and
number of subject and create the array for marks dynamically. write member
function for accepting marks and display all student of marks*/
#include<conio.h>
#include<string.h>
#include<iostream.h>
class student
{
int rno,nos,marks[10];
char name[20];
public:student(int r,char n[20],int no);
       void display();

};
student::student(int r,char n[20],int no)
       {
    int i;
    int *p;
    nos=no;
    p=new int[no];
    cout<<"\nenter marks of "<<no<<"  subject:-";
    for(i=0;i<no;i++)
    {
    cin>>p[i];
    marks[i]=p[i];
    }
    rno=r;
    strcpy(name,n);
    nos=no;
    }
void student::display()
    {
    int i;
    cout<<"\nrollno:-"<<rno<<"\nname:-"<<name
    <<"\nnumber of subject:-"<<nos;
    for(i=0;i<nos;i++)
    {
    cout<<"\nmarks"<<i+1<<":-"<<marks[i];
    }
    }
int main()
{
int n,i;
clrscr();
student s1(2,"amar",3),s2(4,"ajay",4),s3(5,"akal",2);
s1.display();
s2.display();
s3.display();
getch();
return 0;
}

No comments: