/*write a c++ program to create a class student containing data member
-rollno
-name
-marks1,marks2,marks3
write a necessary member function
1.to accept details
2.to display details of one student
3.to display details of all student
*/
#include<conio.h>
#include<iostream.h>
#include<string.h>
class student
{
public:int rollno,m1,m2,m3;
char name[30];
public:void details()
{
int cnt=0;
cout<<"\nenter the student information:-"<<cnt+1;
cout<<"\nenter the rollno:-";
cin>>rollno;
cout<<"\nenter the name:-";
cin>>name;
cout<<"\nenter the marks of three student:-";
cin>>m1>>m2>>m3;
}
void details(char sname[30])
{
cout<<"\nrollno:-"<<rollno
<<"\nname:-"<<sname
<<"\nmarks1:-"<<m1
<<"\nmarks2:-"<<m2
<<"\nmarks3:-"<<m3;
}
void details(int rno,char n[20],int mrk1,int mrk2,int mrk3)
{
cout<<"\nrollno:-"<<rno
<<"\nname:-"<<n
<<"\nmarks1:-"<<mrk1
<<"\nmarks2:-"<<mrk2
<<"\nmarks3:-"<<mrk3;
}
};
int main()
{
student s[3];
int i,cmp,ans=1;
char sn[30];
clrscr();
for(i=0;i<3;i++)
{
s[i].details();
}
cout<<"\nenter student name whose details is to be display:-";
cin>>sn;
cout<<"\ndetails of one student:-";
for(i=0;i<3;i++)
{
cmp=strcmp(sn,s[i].name);
if(cmp==0)
{
ans=0;
s[i].details(sn);
}
}
if(ans!=0)
cout<<"you entered wrong name";
cout<<"\ndetails of all students:-";
for(i=0;i<3;i++)
s[i].details(s[i].rollno,s[i].name,s[i].m1,s[i].m2,s[i].m3);
getch();
return 0;
}
/*
enter the rollno:-12
enter the name:-peer
enter the marks of three student:-3
4
2
enter the student information:-2
enter the rollno:-11
enter the name:-ajay
enter the marks of three student:-4
5
6
enter the student information:-3
enter the rollno:-112
enter the name:-manik
enter the marks of three student:-12
4
5
enter student name whose details is to be display:-peer
details of one student:-
rollno:-12
name:-peer
marks1:-3
marks2:-4
marks3:-2
details of all students:-
rollno:-12
name:-peer
marks1:-3
marks2:-4
marks3:-2
rollno:-11
name:-ajay
marks1:-4
marks2:-5
marks3:-6
rollno:-112
name:-manik
marks1:-12
marks2:-4
marks3:-5
*/
-rollno
-name
-marks1,marks2,marks3
write a necessary member function
1.to accept details
2.to display details of one student
3.to display details of all student
*/
#include<conio.h>
#include<iostream.h>
#include<string.h>
class student
{
public:int rollno,m1,m2,m3;
char name[30];
public:void details()
{
int cnt=0;
cout<<"\nenter the student information:-"<<cnt+1;
cout<<"\nenter the rollno:-";
cin>>rollno;
cout<<"\nenter the name:-";
cin>>name;
cout<<"\nenter the marks of three student:-";
cin>>m1>>m2>>m3;
}
void details(char sname[30])
{
cout<<"\nrollno:-"<<rollno
<<"\nname:-"<<sname
<<"\nmarks1:-"<<m1
<<"\nmarks2:-"<<m2
<<"\nmarks3:-"<<m3;
}
void details(int rno,char n[20],int mrk1,int mrk2,int mrk3)
{
cout<<"\nrollno:-"<<rno
<<"\nname:-"<<n
<<"\nmarks1:-"<<mrk1
<<"\nmarks2:-"<<mrk2
<<"\nmarks3:-"<<mrk3;
}
};
int main()
{
student s[3];
int i,cmp,ans=1;
char sn[30];
clrscr();
for(i=0;i<3;i++)
{
s[i].details();
}
cout<<"\nenter student name whose details is to be display:-";
cin>>sn;
cout<<"\ndetails of one student:-";
for(i=0;i<3;i++)
{
cmp=strcmp(sn,s[i].name);
if(cmp==0)
{
ans=0;
s[i].details(sn);
}
}
if(ans!=0)
cout<<"you entered wrong name";
cout<<"\ndetails of all students:-";
for(i=0;i<3;i++)
s[i].details(s[i].rollno,s[i].name,s[i].m1,s[i].m2,s[i].m3);
getch();
return 0;
}
/*
enter the rollno:-12
enter the name:-peer
enter the marks of three student:-3
4
2
enter the student information:-2
enter the rollno:-11
enter the name:-ajay
enter the marks of three student:-4
5
6
enter the student information:-3
enter the rollno:-112
enter the name:-manik
enter the marks of three student:-12
4
5
enter student name whose details is to be display:-peer
details of one student:-
rollno:-12
name:-peer
marks1:-3
marks2:-4
marks3:-2
details of all students:-
rollno:-12
name:-peer
marks1:-3
marks2:-4
marks3:-2
rollno:-11
name:-ajay
marks1:-4
marks2:-5
marks3:-6
rollno:-112
name:-manik
marks1:-12
marks2:-4
marks3:-5
*/
No comments:
Post a Comment