SlideShare a Scribd company logo
Practical File
Object Oriented
Programming Using C++
Submitted to:
Signature
Submitted by:
P a g e 1
Acknowledgemen
t
I have taken efforts in this practical file. I am highly indebted
to the C++ programming teacher for her guidance and
constant supervision as well as for providing necessary
information regarding the programs and also for her support in
completing the practical file.
I would like to express my gratitude towards my parents for
their kind co-operation and encouragement which helped me
in the completion of this practical file.
My thanks and appreciations also go to my classmates in
developing the practical file and to the people who have
willingly helped me out with their abilities.
Place:
Date:
P a g e 2
Name:
Signature
Table of Contents
S.No. Title Page No. Remarks
1. Program to add two numbers.
2. Program to print first 10 natural
numbers.
3. Program to print sum of first 10 natural
numbers.
4. Program to check whether the entered
number is prime or not.
5. Program to print factorial of a number.
6. Program to print Fibonacci series.
7. Program to check whether the number is
odd or even.
8. Program to print day of the week based
on the day number entered.
9. Program to print first 10 odd natural
numbers using while & do while loop.
10. Program to input a variable in
hexadecimal form and display the
number in different notations like
hexadecimal, octal & decimal.
11. Program to input a variable in octal form
and display the variable in different
number system using setbase(b)
manipulator.
12. Program to calculate the area of a
rectangle using objects & classes.
P a g e 3
13. Program to calculate the area of a
rectangle by defining member function
outside the class.
14. Program to understand the concept of
static data members.
15. Program to show the concept of function
overloading to calculate area where
same name functions differ in number
of
parameters.
16. Program to illustrate the use of
constructor member function to initialize
an object during its creation.
17. Program to initialize an object with
different set of values using
parameterized constructor.
18. Program to understand the use of copy
constructor.
19. Program to demonstrate the use of
constructor overloading and destructor.
20. Program to demonstrate how non-
member function can access private data
members of a class.
21. Program to demonstrate how a friend
function acts as a bridge between two
classes.
22. Program to illustrate that a member
function of one class can act as a friend
of another class.
P a g e 4
23. Program to illustrate how to declare the
entire class as a friend of another class.
24. Program to increment a number by 1
without overloading the operator.
25. Program to overload unary increment
operator (++).
26. Program to overload a unary operator
using friend function.
27. Program to compare the date of birth of
two persons by overloading the equality
operator (==).
28. Program to add two time objects by
overloading += operator.
29. Program to illustrate how to derive a
class from a base class.
30. Program to implement multilevel
inheritance.
31. Program to implement hierarchical
inheritance.
P a g e 5
32. Program to demonstrate multiple
inheritance in which a class is derived
publicly from both the base classes.
33. Program to understand hybrid
inheritance, consider an example of
calculating the result of a student on the
basis of marks obtained in internal and
external examination.
34. Program to calculate the result of the
student using private inheritance.
35. Program to demonstrate the use of
protected members.
36. Program to illustrate the concept of
overriding member functions.
37. Program to maintain student information
by creating a composite class having one
of its data member as an object of
another predefined class.
P a g e 6
P a g e 7
// Program to add two numbers.
#include<iostream.h>
#include<conio.h>
void main(){
int a, b;
clrscr();
cout << "Enter value of a: ";
cin >> a;
cout << "Enter value of b: ";
cin >> b;
cout << "Sum = " << (a + b);
getch();
}
P a g e 8
P a g e 9
// Program to print first 10 natural numbers.
#include<iostream.h>
#include<conio.h>
void main(){
int i;
clrscr();
cout << "First 10 natural numbers: ";
for(i = 1; i <= 10; i++)
cout << i << " ";
getch();
}
P a g e 10
P a g e 11
// Program to print sum of first 10 natural numbers.
#include<iostream.h>
#include<conio.h>
void main(){
int i, sum = 0;
clrscr();
cout << "First 10 natural numbers: ";
for(i = 1; i <= 10; i++){
cout << i << " ";
sum += i;
}
cout << "nSum = " << sum;
getch();
}
P a g e 12
P a g e 13
// Program to check whether the entered number is prime or not.
#include<iostream.h>
#include<conio.h>
void main(){
int i, num, count = 0;
clrscr();
cout << "Enter any number: ";
cin >> num;
for(i = 1; i <= num; i++)
{ if((num % i) == 0)
count++;
}
if(count == 2)
cout << num << " is a prime number.";
else
cout << num << " is not a prime number.";
getch();
}
P a g e 14
P a g e 15
// Program to print factorial of a number.
#include<iostream.h>
#include<conio.h>
void main(){
clrscr();
int i, num, fact = 1;
cout << "nEnter any number: ";
cin >> num;
for(i = 1; i <= num; i++)
fact *= i;
cout << "Factorial of " << num << " = " << fact;
getch();
}
P a g e 16
P a g e 17
// Program to print Fibonacci series.
#include<iostream.h>
#include<conio.h>
void main(){
int i, n, a = 0, b = 1, c;
clrscr();
cout << "Enter no. of terms: ";
cin >> n;
if(n == 1)
cout << "Fibonacci series: " << a << " ";
else
cout << "Fibonacci series: " << a << " " << b << " ";
for(i = 3; i <= n; i++){
c = a + b;
cout << c << " ";
a = b;
b = c;
}
getch();
}
P a g e 18
P a g e 19
// Program to check whether the no. is odd or even.
#include<iostream.h>
#include<conio.h>
void main(){
int num;
clrscr();
cout << "Enter a number: ";
cin >> num;
if((num % 2) == 0)
cout << num << " is an even number.";
else
cout << num << " is an odd number.";
getch();
}
P a g e 20
P a g e 21
// Program to print day of the week based on the day number entered.
#include<iostream.h>
#include<conio.h>
void main(){
int dnum;
clrscr();
cout << "Enter any day number (1-7): ";
cin >> dnum;
switch(dnum){
case 1: cout << "Sunday";
break;
case 2: cout << "Monday";
break;
case 3: cout << "Tuesday";
break;
case 4: cout << "Wednesday";
break;
case 5: cout << "Thursday";
break;
case 6: cout << "Friday";
break;
case 7: cout << "Saturday";
break;
default: cout << "Invalid day no.";
}
getch();
}
P a g e 22
P a g e 23
// Program to print first 10 odd natural numbers using while & do while
loop.
#include<iostream.h>
#include<conio.h>
void main(){
clrscr();
int i = 1, x = 1;
cout << "While loop: " << endl;
cout << "First 10 odd natural numbers: ";
while(i <= 10){
cout << x << " ";
x += 2;
i++;
}
i = 1; x = 1; cout << "nnDo while loop: " << endl;
cout << "First 10 odd natural numbers: ";
do{
cout << x << " ";
x += 2;
i++;
}while(i <= 10);
getch();
}
P a g e 24
Practical File of c++.docx lab manual program question
P a g e 25
// Program to enter a variable in hexadecimal form and display the
number in different notations like hexadecimal, octal & decimal.
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void main(){
clrscr();
int i;
cout << "nEnter a hexadecimal no.:
"; cin >> hex >> i;
cout << "nValue in hex format = " << hex <<
i; cout << "nValue in octal format = " << oct
<< i; cout << "nValue in decimal format = " <<
dec << i; getch();
}
P a g e 26
P a g e 27
// Program to input a variable in octal form and display the variable in
different number system using setbase(b).
. #include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void main(){
clrscr();
int
num;
cout << "nEnter value of num in octal form:
"; cin >> setbase(8) >> num;
cout << "nValue in hex form = " << setbase(16) << num;
cout << "nValue in oct form = " << setbase(8) << num;
cout << "nValue in dec form = " << setbase(10) << num;
getch();
}
P a g e 28

More Related Content

Similar to Practical File of c++.docx lab manual program question (20)

PDF
CBSE Question Paper Computer Science with C++ 2011
Deepak Singh
 
DOCX
C++ file
Mukund Trivedi
 
DOCX
C++ file
Mukund Trivedi
 
DOC
project report in C++ programming and SQL
vikram mahendra
 
PDF
Object Oriented Programming using C++ PCIT102.pdf
GauravKumar295392
 
PDF
c++ practical Digvajiya collage Rajnandgaon
yash production
 
PDF
Basic Elements of C++
Jason J Pulikkottil
 
PPT
Apclass (2)
geishaannealagos
 
PPT
Apclass (2)
geishaannealagos
 
PPT
Elementary_Of_C++_Programming_Language.ppt
GordanaJovanoska1
 
PPT
Basic concept of c++
shashikant pabari
 
DOCX
C++ program: All tasks .cpp
Khalid Waleed
 
PPT
Apclass
geishaannealagos
 
PDF
C++ How to Program 10th Edition Deitel Solutions Manual
jovaerili
 
DOCX
Computer Practical XII
Ûťţåm Ğűpţä
 
PDF
C++ TUTORIAL 2
Farhan Ab Rahman
 
DOC
programming in C++ report
vikram mahendra
 
DOCX
Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org) (usef...
Make Mannan
 
PDF
Programming in C 2nd Edition Safari download pdf
pemlaikiz
 
CBSE Question Paper Computer Science with C++ 2011
Deepak Singh
 
C++ file
Mukund Trivedi
 
C++ file
Mukund Trivedi
 
project report in C++ programming and SQL
vikram mahendra
 
Object Oriented Programming using C++ PCIT102.pdf
GauravKumar295392
 
c++ practical Digvajiya collage Rajnandgaon
yash production
 
Basic Elements of C++
Jason J Pulikkottil
 
Apclass (2)
geishaannealagos
 
Apclass (2)
geishaannealagos
 
Elementary_Of_C++_Programming_Language.ppt
GordanaJovanoska1
 
Basic concept of c++
shashikant pabari
 
C++ program: All tasks .cpp
Khalid Waleed
 
C++ How to Program 10th Edition Deitel Solutions Manual
jovaerili
 
Computer Practical XII
Ûťţåm Ğűpţä
 
C++ TUTORIAL 2
Farhan Ab Rahman
 
programming in C++ report
vikram mahendra
 
Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org) (usef...
Make Mannan
 
Programming in C 2nd Edition Safari download pdf
pemlaikiz
 

Recently uploaded (20)

PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PDF
SSHS-2025-PKLP_Quarter-1-Dr.-Kerby-Alvarez.pdf
AishahSangcopan1
 
PPTX
Views on Education of Indian Thinkers Mahatma Gandhi.pptx
ShrutiMahanta1
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PPTX
Pyhton with Mysql to perform CRUD operations.pptx
Ramakrishna Reddy Bijjam
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PPTX
Mathematics 5 - Time Measurement: Time Zone
menchreo
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PPTX
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PPSX
Health Planning in india - Unit 03 - CHN 2 - GNM 3RD YEAR.ppsx
Priyanshu Anand
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
SSHS-2025-PKLP_Quarter-1-Dr.-Kerby-Alvarez.pdf
AishahSangcopan1
 
Views on Education of Indian Thinkers Mahatma Gandhi.pptx
ShrutiMahanta1
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
Pyhton with Mysql to perform CRUD operations.pptx
Ramakrishna Reddy Bijjam
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
Mathematics 5 - Time Measurement: Time Zone
menchreo
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
Health Planning in india - Unit 03 - CHN 2 - GNM 3RD YEAR.ppsx
Priyanshu Anand
 
Ad

Practical File of c++.docx lab manual program question

  • 1. Practical File Object Oriented Programming Using C++ Submitted to: Signature Submitted by: P a g e 1
  • 2. Acknowledgemen t I have taken efforts in this practical file. I am highly indebted to the C++ programming teacher for her guidance and constant supervision as well as for providing necessary information regarding the programs and also for her support in completing the practical file. I would like to express my gratitude towards my parents for their kind co-operation and encouragement which helped me in the completion of this practical file. My thanks and appreciations also go to my classmates in developing the practical file and to the people who have willingly helped me out with their abilities. Place: Date: P a g e 2
  • 4. Table of Contents S.No. Title Page No. Remarks 1. Program to add two numbers. 2. Program to print first 10 natural numbers. 3. Program to print sum of first 10 natural numbers. 4. Program to check whether the entered number is prime or not. 5. Program to print factorial of a number. 6. Program to print Fibonacci series. 7. Program to check whether the number is odd or even. 8. Program to print day of the week based on the day number entered. 9. Program to print first 10 odd natural numbers using while & do while loop. 10. Program to input a variable in hexadecimal form and display the number in different notations like hexadecimal, octal & decimal. 11. Program to input a variable in octal form and display the variable in different number system using setbase(b) manipulator. 12. Program to calculate the area of a rectangle using objects & classes. P a g e 3
  • 5. 13. Program to calculate the area of a rectangle by defining member function outside the class. 14. Program to understand the concept of static data members. 15. Program to show the concept of function overloading to calculate area where same name functions differ in number of parameters. 16. Program to illustrate the use of constructor member function to initialize an object during its creation. 17. Program to initialize an object with different set of values using parameterized constructor. 18. Program to understand the use of copy constructor. 19. Program to demonstrate the use of constructor overloading and destructor. 20. Program to demonstrate how non- member function can access private data members of a class. 21. Program to demonstrate how a friend function acts as a bridge between two classes. 22. Program to illustrate that a member function of one class can act as a friend of another class. P a g e 4
  • 6. 23. Program to illustrate how to declare the entire class as a friend of another class. 24. Program to increment a number by 1 without overloading the operator. 25. Program to overload unary increment operator (++). 26. Program to overload a unary operator using friend function. 27. Program to compare the date of birth of two persons by overloading the equality operator (==). 28. Program to add two time objects by overloading += operator. 29. Program to illustrate how to derive a class from a base class. 30. Program to implement multilevel inheritance. 31. Program to implement hierarchical inheritance. P a g e 5
  • 7. 32. Program to demonstrate multiple inheritance in which a class is derived publicly from both the base classes. 33. Program to understand hybrid inheritance, consider an example of calculating the result of a student on the basis of marks obtained in internal and external examination. 34. Program to calculate the result of the student using private inheritance. 35. Program to demonstrate the use of protected members. 36. Program to illustrate the concept of overriding member functions. 37. Program to maintain student information by creating a composite class having one of its data member as an object of another predefined class. P a g e 6
  • 8. P a g e 7
  • 9. // Program to add two numbers. #include<iostream.h> #include<conio.h> void main(){ int a, b; clrscr(); cout << "Enter value of a: "; cin >> a; cout << "Enter value of b: "; cin >> b; cout << "Sum = " << (a + b); getch(); } P a g e 8
  • 10. P a g e 9
  • 11. // Program to print first 10 natural numbers. #include<iostream.h> #include<conio.h> void main(){ int i; clrscr(); cout << "First 10 natural numbers: "; for(i = 1; i <= 10; i++) cout << i << " "; getch(); } P a g e 10
  • 12. P a g e 11
  • 13. // Program to print sum of first 10 natural numbers. #include<iostream.h> #include<conio.h> void main(){ int i, sum = 0; clrscr(); cout << "First 10 natural numbers: "; for(i = 1; i <= 10; i++){ cout << i << " "; sum += i; } cout << "nSum = " << sum; getch(); } P a g e 12
  • 14. P a g e 13
  • 15. // Program to check whether the entered number is prime or not. #include<iostream.h> #include<conio.h> void main(){ int i, num, count = 0; clrscr(); cout << "Enter any number: "; cin >> num; for(i = 1; i <= num; i++) { if((num % i) == 0) count++; } if(count == 2) cout << num << " is a prime number."; else cout << num << " is not a prime number."; getch(); } P a g e 14
  • 16. P a g e 15
  • 17. // Program to print factorial of a number. #include<iostream.h> #include<conio.h> void main(){ clrscr(); int i, num, fact = 1; cout << "nEnter any number: "; cin >> num; for(i = 1; i <= num; i++) fact *= i; cout << "Factorial of " << num << " = " << fact; getch(); } P a g e 16
  • 18. P a g e 17
  • 19. // Program to print Fibonacci series. #include<iostream.h> #include<conio.h> void main(){ int i, n, a = 0, b = 1, c; clrscr(); cout << "Enter no. of terms: "; cin >> n; if(n == 1) cout << "Fibonacci series: " << a << " "; else cout << "Fibonacci series: " << a << " " << b << " "; for(i = 3; i <= n; i++){ c = a + b; cout << c << " "; a = b; b = c; } getch(); } P a g e 18
  • 20. P a g e 19
  • 21. // Program to check whether the no. is odd or even. #include<iostream.h> #include<conio.h> void main(){ int num; clrscr(); cout << "Enter a number: "; cin >> num; if((num % 2) == 0) cout << num << " is an even number."; else cout << num << " is an odd number."; getch(); } P a g e 20
  • 22. P a g e 21
  • 23. // Program to print day of the week based on the day number entered. #include<iostream.h> #include<conio.h> void main(){ int dnum; clrscr(); cout << "Enter any day number (1-7): "; cin >> dnum; switch(dnum){ case 1: cout << "Sunday"; break; case 2: cout << "Monday"; break; case 3: cout << "Tuesday"; break; case 4: cout << "Wednesday"; break; case 5: cout << "Thursday"; break; case 6: cout << "Friday"; break; case 7: cout << "Saturday"; break; default: cout << "Invalid day no."; } getch(); } P a g e 22
  • 24. P a g e 23
  • 25. // Program to print first 10 odd natural numbers using while & do while loop. #include<iostream.h> #include<conio.h> void main(){ clrscr(); int i = 1, x = 1; cout << "While loop: " << endl; cout << "First 10 odd natural numbers: "; while(i <= 10){ cout << x << " "; x += 2; i++; } i = 1; x = 1; cout << "nnDo while loop: " << endl; cout << "First 10 odd natural numbers: "; do{ cout << x << " "; x += 2; i++; }while(i <= 10); getch(); } P a g e 24
  • 27. P a g e 25 // Program to enter a variable in hexadecimal form and display the number in different notations like hexadecimal, octal & decimal. #include<iostream.h> #include<conio.h> #include<iomanip.h> void main(){ clrscr(); int i; cout << "nEnter a hexadecimal no.: "; cin >> hex >> i; cout << "nValue in hex format = " << hex << i; cout << "nValue in octal format = " << oct << i; cout << "nValue in decimal format = " << dec << i; getch(); } P a g e 26
  • 28. P a g e 27
  • 29. // Program to input a variable in octal form and display the variable in different number system using setbase(b). . #include<iostream.h> #include<conio.h> #include<iomanip.h> void main(){ clrscr(); int num; cout << "nEnter value of num in octal form: "; cin >> setbase(8) >> num; cout << "nValue in hex form = " << setbase(16) << num; cout << "nValue in oct form = " << setbase(8) << num; cout << "nValue in dec form = " << setbase(10) << num; getch(); } P a g e 28