Write File Operation Using C++
Programming
#include
#include
#include
#include
void main()
{
char c,fname[10];
ofstream out;
cout<<"Enter File name:";
cin>>fname;
out.open(fname);
cout<<"Enter contents to store in
file (Enter # at end):\n";
while((c=getchar())!='#')
{
out<
}
out.close();
getch();
}
Output
Enter File name:
one.txt
Enter contents to
store in file (enter # at end)
Master of Computer
Applications#
Virtual Functions Using C++ Programming
#include
#include
class base
{
public:
virtual void show()
{
cout<<"\n Base class
show:";
}
void display()
{
cout<<"\n Base class
display:" ;
}
};
class drive:public
base
{
public:
void display()
{
cout<<"\n Drive class
display:";
}
void show()
{
cout<<"\n Drive class
show:";
}
};
void main()
{
clrscr();
base
obj1;
base *p;
cout<<"\n\t P points to base:\n" ;
p=&obj1;
p->display();
p->show();
cout<<"\n\n\t
P points to drive:\n";
drive
obj2;
p=&obj2;
p->display();
p->show();
getch();
}
Output
P points to Base
Base class display
Base class show
P points to Drive
Base class Display
Drive class Show
Virtual Base Class Using C++ Programming
#include
#include
class student
{
int rno;
public:
void getnumber()
{
cout<<"Enter Roll No:";
cin>>rno;
}
void putnumber()
{
cout<<"\n\n\tRoll
No:"<
}
};
class test:virtual public student
{
public:
int part1,part2;
void getmarks()
{
cout<<"Enter Marks\n";
cout<<"Part1:";
cin>>part1;
cout<<"Part2:";
cin>>part2;
}
void putmarks()
{
cout<<"\tMarks Obtained\n";
cout<<"\n\tPart1:"<
cout<<"\n\tPart2:"<
}
};
class sports:public virtual student
{
public:
int score;
void getscore()
{
cout<<"Enter Sports Score:";
cin>>score;
}
void putscore()
{
cout<<"\n\tSports Score is:"<
}
};
class result:public test,public sports
{
int total;
public:
void display()
{
total=part1+part2+score;
putnumber();
putmarks();
putscore();
cout<<"\n\tTotal Score:"<
}
};
void main()
{
result obj;
clrscr();
obj.getnumber();
obj.getmarks();
obj.getscore();
obj.display();
getch();
}
Output
Enter Roll No: 200
Enter Marks
Part1: 90
Part2: 80
Enter Sports Score: 80
Roll No: 200
Marks Obtained
Part1: 90
Part2: 80
Sports Score is: 80
Total Score is: 250
No comments:
Post a Comment