You are on page 1of 16

C++ Programming

1. Explain a. Objects b. Classes c. Data abstraction and encapsulation


d. Inheritance e. Polymorphism f. Dynamic binding g. Message passing
2. What are the benefits of OOP
3. Explain Procedure oriented programming(POP) language
4. Explain the size of different data type
5. Conversion of bite to Byte, KiloByte, MegaByte
6. Explain different types of operator used in C++
7. Explain what do you understand by Type casting
8. What do you understand by machine level language, assembly level
language and high level language?
9. What are the Types of conditional statements used in C++ (also explain
the syntax used)
10.Explain Object oriented programming(OOP) language.
11.What are the Character Set used in C++
12.Whats do you understand by keywords, Veriables, Primitive Data type,
Identifier
13.What is difference between Break, Continue statement
14.What are the Types of Control Structure in C++
15.Explain Class and object with example

Page 1
C++ Programming

Programs
1) Write a simple C program to display “Hello World” message on the
screen.
#include <iostream>
using namespace std;

int main()
{
// prints hello world
cout << "Hello World";

return 0;
}

2) Write a program to display information about yourself such as “Name:


Roll Number: Class: Div”

3) Write a program to display following banner using simple C printf


statements.
|==============================================|
| WALCHAND INSTITUTE OF TECHNOLOGY |
| SOLAPUR |
|==============================================|

Page 2
C++ Programming

4) Write a program to calculate average of three numbers.


#include<iostream>
using namespace std;
int main() {
int num_1;
cout << "Enter num_1 : ";
cin >> num_1;
int num_2;
cout << "Enter num_2 : ";
cin >> num_2;
int num_3;
cout << "Enter num_3 : ";
cin >> num_3;
float average = (num_1 + num_2 + num_3) / 3;
cout << "Average : " << average << endl;
}

Page 3
C++ Programming

5) Write a program to perform arithmetic operations such as addition,


subtraction, division and multiplication on two numbers a=10 and b=20
#include<iostream>
using namespace std;
int main()
{
int a=10;
int b=20;
int sum;
sum=a+b;
cout<<"The sum = "<<sum;
return 0;
}

Page 4
C++ Programming

6) Write a program to calculate square of given number.


#include<iostream>

using namespace std;

int main()

int number, square;

cout << "\nPlease Enter Number to find Square of it = ";

cin >> number;

square = number * number;

cout << "\nThe Square of the Given " << number << " = " << square;

return 0;

Page 5
C++ Programming

7) Write a program to calculate area and perimeter of a square.

#include<iostream>
using namespace std;
int main()
{
int length, area, peri;
cout<<"Enter the length of square = ";
cin>>length;
area=length*length;
peri=4*length;
cout<<"area = "<<area<<"\n";
cout<<"perimeter= "<<peri;
return 0;
}

Page 6
C++ Programming

8) Write a program to read given two numbers from user and perform arithmetic
operations such as addition, subtraction, multiplication, division and modulus
division and display results of respective.
#include<iostream>
using namespace std;
int main()
{
int x,y;
cout<<"enter fist value = ";
cin>>x;
cout<<"enter second value = ";
cin>>y;
int sum=x+y;
int sub=x-y;
int mul=x*y;
float div=(float)x/y;
float mod=x%y;
cout<<"The Summation is = "<<sum;
cout<<"\nThe Subtraction is = "<<sub;
cout<<"\nThe Multiplication is = "<<mul;
cout<<"\nThe Division is = "<<div;
cout<<"\nThe Modulus is = "<<mod;

return 0;
}

Page 7
C++ Programming

9) Write a program to convert temperature from degree Celsius to Fahrenheit.


[Concept Note: fahrenheit = ((9/5) * celsius) + 32]
#include <iostream>
using namespace std;
int main()
{
float x, y;
cout << "Enter the temperature in celsius\n";
cin >> x;
y =(9.0/5.0) * x + 32;
cout << x <<"Centigrade is equal to " << y <<"Fahrenheit";
return 0;
}

10) Write a program to convert temperature from Fahrenheit to degree Celsius.


[Concept Note: degree = (fahrenheit -32)*5/9]

Page 8
C++ Programming

11) Write a program to convert meter to kilometer and centimeter.


#include<iostream>
using namespace std;
int main()
#include<iostream>
using namespace std;
int main()
{
float x,y,z;
cout<<"enter value in meter = ";
cin>>x;
y=x*1/1000.0;
cout<<x<< " meter equal to "<<y<<" kilometer\n";
z=x*100.0;
cout<<x<< " meter equal to "<<z<<" centimeter";
return 0;
}

12) Write a program to convert centimeter to meter and meter to centimeter.

Page 9
C++ Programming

13) Write a program to display table of given number.


#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter a positive integer: ";
cin >> n;
// run a loop from 1 to 10
// print the multiplication table
for (int i = 1; i <= 10; ++i) {
cout << n << " * " << i << " = " << n * i << endl;
}
return 0;
}

Page 10
C++ Programming

14) Write a program to display student’s grade “Pass” if marks is greater than or
equal to 40 and display “Fail” if marks is less than 40.
#include <iostream>
using namespace std;
int main()
{
int marks;
cout<<"enter marks "<<endl;
cin>>marks;
if(marks>=40)
{
cout<<"Pass "<<endl;
}
else
{
cout<<"fail";
}
return 0;
}

Page 11
C++ Programming

15) Write a program to decide given number is ODD or EVEN number.


#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter an integer: ";
cin >> n;
if ( n % 2 == 0)
cout << n << " is even.";
else
cout << n << " is odd.";
return 0;
}

Page 12
C++ Programming

16) Write a program using if statement


i) To display message if given number is greater than 10 using if statement.

#include <iostream>

using namespace std;

int main() {

int number;

cout << "Enter an integer: ";

cin >> number;

if (number > 10) {

cout << "Entered a number is greater than 10";

return 0;

Page 13
C++ Programming

ii) To calculate area of circle if given radius value is not equal to zero.

#include <iostream>

using namespace std;

int main() {

float radius, area_circle;

cout << "Enter the radius of circle: ";

cin >> radius;

if(radius>0)

area_circle = 3.14 * radius * radius;

cout << "Area of circle: " << area_circle << endl;

return 0;

Page 14
C++ Programming

17) Write a program using if_else statement


i) To read person‟s age and decide whether that person is eligible for voting or
not and accordingly display messages.
#include<iostream>
using namespace std;
int main()
{
int age;
cout<<"Enter your age: ";
cin>>age;
if(age>=18)
{
cout<<"Personl is eligible for voting"<<endl;
}
else
{
cout<<"Person is not eligible for voating"<<endl;
}

return 0;
}

Page 15
C++ Programming

ii) To check that user entered number is positive or negative and accordingly
display messages.
#include<iostream>
using namespace std;
int main ()
{
int num;
cout << "Enter the number to be checked : ";
cin >> num;
if (num >= 0)
cout << num << " is a positive number.";
else
cout << num << " is a negative number.";
return 0;
}

Page 16

You might also like