C++ File For Print Out
C++ File For Print Out
College, Sirsa
Practical file
Of
Programming in C++
Submittd To: SubmittedBy:
Mr. Mohit Aadish Kumar
Asst.Professor Class: BCA 2nd SEM
#include<iostream>
int main()
int a, b, result;
cin>>a;
cin>>b;
result = a*a+b*b+2*a*b;
return 0;
}
Output
// Write a program to findout factorial of a number
#include<iostream>
int main()
cin>>number;
fact=fact*i;
return 0;
}
Output
// write a program to find largest number among three numbers
#include<iostream>
int main()
else
return 0;
}
Output
// Write a program to class implementation ( simple class and objects)
#include<iostream>
class Rect{
public:
double length;
double breadth;
double calculateArea(){
};
int main()
Rect rect1;
rect1.length = 32.5;
rect1.breadth = 20.8;
return 0;
}
Output
// Write a program to add give time using objects as arguments
#include <iostream>
class Time {
private:
int hours;
int minutes;
public:
Time(int h, int m) {
hours = h;
minutes = m;
void addTime(Time t) {
minutes += t.minutes;
minutes %= 60;
hours %= 24;
void displayTime() {
std::cout << "Time: " << hours << " hours " << minutes << " minutes" <<
std::endl;
};
int main() {
t1.displayTime();
t2.displayTime();
t1.addTime(t2);
t1.displayTime();
return 0;
}
Output
// Write a program swapping two number without using 3rd (temporary)
variable
#include<iostream>
int main()
int a,b;
cin>>a;
cin>>b;
a = a + b;
b = a - b;
a = a - b;
cout<<"\n\nValue After Swapping :\n"<<endl;
cout<<"\n\n\n";
return 0;
}
Output
// Write a program to print a table of given number
#include<iostream>
int main()
int number;
cin>>number;
cout<<number<<"*"<<i<<"="<<number*i<<endl;
Return 0;
}
Output
// Write a program class with constructor
#include<iostream>
class student {
int rno;
char name[50];
double fee;
public:
student()
void display()
cout << endl << rno << "\t" << name << "\t" << fee;
}
};
int main()
student s;
s.display();
return 0;
}
Output
// Write a program multi-level inheritance
#include<iostream>
class Vehicle{
public:
void Name1(){
};
public:
void Name2(){
};
public:
void Name3(){
};
int main()
Car obj;
obj.Name3();
obj.Name2();
obj.Name1();
return 0;
}
Output
// Write a program hybrid inheritance
#include<iostream>
class animal{
public:
animal(){
};
public:
cat(){
};
class pet{
public:
pet(){
cout<<"and pet";
};
class kitty: public cat, public pet{
public:
kitty(){
};
int main()
kitty mycat;
return 0;
}
Output
// Write a program to illustrates the use of pointers to objects
#include<iostream>
class box{
public:
length = l;
breadth = b;
height = h;
double volume(){
private:
double length;
double breadth;
double height;
};
int main()
box *ptrbox;
ptrbox = &box1;
ptrbox = &box2;
return 0;
}
Output
// Write a program virtual function
#include<iostream>
class Base{
public:
};
public:
void print(){
};
int main()
Derived derived1;
Base * base = &derived1;
return 0;
}
Output
//Write a program working with single-file
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
int main()
clrscr();
ofstream outf("ITEM");
cin>>name;
outf<<name<<"\n";
float cost;
cin>>cost;
outf<<cost<<"\n";
outf.close();
ifstream inf("ITEM");
inf>>name;
inf>>cost;
cout<<"Item name:"<<name<<"\n";
cout<<"Item cost:"<<cost<<"\n";
inf.close();
getch();
return 0;
}
Output
// Write a program working with multi-files
#include<iostream>
#include<fstream>
int main()
ofstream fout;
fpot.open("Country");
fout<<"United Kingdom\n";
fout<<"South Korea\n";
fout.close();
fout.open("Captial");
fout<<"Washington\n";
fout<<"London\n";
fout<<"Seoul\n";
ifstream fin;
fin.open("Country");
while(fin)
fin.getline(line, N);
cout<<line;
fin.close();
return 0;
}
Output