Read File Operation Using C++ Programming
#include
#include
#include
void main()
{
char c,fname[10];
clrscr();
cout<<"Enter file name:";
cin>>fname;
ifstream in(fname);
if(!in)
{
cout<<"File Does not Exist";
getch();
return;
}
cout<<"\n\n";
while(in.eof()==0)
{
in.get(c);
cout<
}
getch();
}
Output
Enter File name:
one.txt
Master of Computer Applications
Read & Write File Operation (Convert lowercase to uppercase) Using C++ Programming
#include
#include
#include
#include
#include
#include
void main()
{
char c,u;
char fname[10];
clrscr();
ofstream out;
cout<<"Enter File Name:";
cin>>fname;
out.open(fname);
cout<<"Enter the text(Enter # at end)\n";
while((c=getchar())!='#')
{
u=c-32;
out<
}
out.close();
ifstream in(fname);
cout<<"\n\n\t\tThe File contains\n\n";
while(in.eof()==0)
{
in.get(c);
cout<
}
getch();
}
Output
Enter File Name:
two.txt
Enter contents to
store in file (enter # at end)
oops programming
The File Contains
Oops programming
Multiple Inheritance Using C++ Programming
#include
#include
class student
{
protected:
int rno,m1,m2;
public:
void get()
{
cout<<"Enter the Roll no :";
cin>>rno;
cout<<"Enter the two marks :";
cin>>m1>>m2;
}
};
class sports
{
protected:
int sm;
public:
void getsm()
{
cout<<"\nEnter the sports
mark :";
cin>>sm;
}
};
class statement:public
student,public sports
{
int
tot,avg;
public:
void display()
{
tot=(m1+m2+sm);
avg=tot/3;
cout<<"\n\n\tRoll No
: "<
cout<<"\n\tAverage :
"<
}
};
void main()
{
clrscr();
statement
obj;
obj.get();
obj.getsm();
obj.display();
getch();
}
Output
Enter the Roll no: 100
Enter two marks
90
80
Enter the Sports Mark: 90
Roll No: 100
Total : 260
Average: 86.66
Inline Function Using C++ Programming
#include
#include
class line
{
public:
inline float mul(float x,float y)
{
return(x*y);
}
inline float cube(float x)
{
return(x*x*x);
}
};
void main()
{
line obj;
float val1,val2;
clrscr();
cout<<"Enter two values:";
cin>>val1>>val2;
cout<<"\nMultiplication value
is:"<
cout<<"\n\nCube value is
:"<
getch();
}
Output
Enter two values: 5
7
Multiplication Value is: 35
Cube Value is: 25 and 343
No comments:
Post a Comment