#include<iostream.h>
#include<conio.h>
class student
{
int rn,m1,m2,total;
char nm[20];
public:
void getdata()
{
cout<<"Enter RollNo.:";
cin>>rn;
cout<<"Enter Name:";
cin>>nm;
cout<<"Enter m1 & m2:";
cin>>m1>>m2;
}
void putdata();
};
void stud :: putdata()
{
cout<<"\nRoll no.:"<<rn;
cout<<"\nName:"<<nm;
cout<<"\nM1:"<<m1;
cout<<"\nM2:"<<m2;
cout<<"\nTotal:"<<total;
}
int main()
{
student s;
clrscr();
s.getdata();
s.putdata();
getch();
return 0;
}
#include<conio.h>
class student
{
int rn,m1,m2,total;
char nm[20];
public:
void getdata()
{
cout<<"Enter RollNo.:";
cin>>rn;
cout<<"Enter Name:";
cin>>nm;
cout<<"Enter m1 & m2:";
cin>>m1>>m2;
}
void putdata();
};
void stud :: putdata()
{
cout<<"\nRoll no.:"<<rn;
cout<<"\nName:"<<nm;
cout<<"\nM1:"<<m1;
cout<<"\nM2:"<<m2;
cout<<"\nTotal:"<<total;
}
int main()
{
student s;
clrscr();
s.getdata();
s.putdata();
getch();
return 0;
}
Hi Nik.
ReplyDeleteI suggest you to not use system dependent functions like "clrscr" or "getch" defined in the "conio.h" header file because it is not a standard c++ neither standard c header file (on linux and unix like OSes the header file "conio.h" does not exist).
In linux or unix like systems (freebsd, mac osx...) there is no standard replacemente for "clrscr" but you can use "getchar" instead of "getch". "getchar" is defined in "stdio.h" but on most systems the user must press "enter" after the key to take effect.
Congrats for the blog.
Thanks Avelino for pointing out that.. :)
Delete