Lab Manual: Department of Computer Science & Engineering School of Engineering & Technology
Lab Manual: Department of Computer Science & Engineering School of Engineering & Technology
Lab Manual: Department of Computer Science & Engineering School of Engineering & Technology
3. Program in C++ to input marks in 5 subjects & calculate aggregate & percentage.
4. Program in C++ to find out whether the given number is odd or even
5. Program in C++ to find out whether the given year is a leap year or not
8. Program in C++ for swapping of two numbers with & without using 3rd variable.
switch(ch)
{
case 1:
{
cout<<“nEnter radius of the circle:”;
cin>>r;
area=3.14*r*r;
break;
}
case 2:
{
cout<<“nEnter length and breadth:”;
cin>>a>>b;
area=a*b;
break;
}
case 3:
{
cout<<“nEnter three sides of the triangle:”;
cin>>a>>b>>c;
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
break;
}
default:
cout<<“nWrong choice…!!!”;
break;
}
cout<<“Area=”<<area;
getch(); //to stop the screen
}
Viva-Voce Questions
Q1: What is c++?
Ans: c++ is a general purpose object oriented programming language invented in the early 1980 by bajarne
stroutrup.
Viva-Voce Questions
Q1. What is the difference between C & C++?
Ans. C++ is an object oriented programing but c is a procedure oriented programing. C is super set of
C++. C can’t support inheritance, function overloading, method overloading etc. but C++ can do this. In c-
program the main function could not return a value but in the C++ the main function should return a value.
Viva-Voce Questions
Q1.Differentiate between for loop and a while loop? What are it uses?
Ans: For executing a set of statements fixed number of times we use for loop while when the
number of iterations to be performed is not known in advance we use while loop.
Viva-Voce Questions
Q1.What is the scope resolution operator?
Ans. The scope resolution operator is used to
Resolve the scope of global variables.
To associate function definition to a class if the function is defined outside the class.
Q5. What are the major differences between Object Oriented Programming and Procedural Programming?
Ans. Object Oriented Programming
*Emphasis on data
*Follow bottom up approach in program design
*Concept of Data hiding prevents accidental change in the data
*Polymorphism, inheritance, Data Encapsulation possible
Procedural Programming
*Emphasis on doing things (function)
*Follow top-down approach in program design
*Due to presence of global variables, there are possibilities of accidental change in data
Program 6: Program in C++ to find out the maximum out of three numbers
#include <iostream>
void main()
{
float n1, n2, n3;
cout << "Enter three numbers: ";
cin >> n1 >> n2 >> n3;
if(n1 >= n2 && n1 >= n3)
{
cout << "Largest number: " << n1;
}
if(n2 >= n1 && n2 >= n3)
{
cout << "Largest number: " << n2;
}
if(n3 >= n1 && n3 >= n2)
{
cout << "Largest number: " << n3;
}
}
Viva-Voce Questions
Q1. What are constants?
Constants are data items whose values cannot be changed.
A constant is of numeric or non-numeric type.
Numeric constants consist of only numbers, either whole numbers or decimal numbers.
Integer, floating point are numeric constants.
Viva-Voce Questions
Q1. What is Inheritance
Ans. Inheritance is the process of acquiring the properties of the existing class into the new class. The
existing class is called as base/parent class and the inherited class is called as derived/child class.
Q2.What is encapsulation?
Ans. The process of binding the data and the functions acting on the data together in an entity (class) called
as encapsulation.
Q5. What is the difference between the keywords struct and class in C++?
Ans. By default the members of struct are public and by default the members of the class are private.
Program 8: Program in C++ for swapping of two numbers with and without using 3rd variable.
#include <iostream>
void main()
{
int a = 5, b = 10, temp;
cout << "Before swapping." << endl;
cout << "a = " << a << ", b = " << b << endl;
temp = a;
a = b;
b = temp;
cout << "\nAfter swapping." << endl;
cout << "a = " << a << ", b = " << b << endl;
}
WITHOUT USING THIRD VARIABLE
#include <iostream>
void main()
{
int a = 5, b = 10;
cout << "Before swapping." << endl;
cout << "a = " << a << ", b = " << b << endl;
a = a + b;
b = a - b;
a = a - b;
cout << "\nAfter swapping." << endl;
cout << "a = " << a << ", b = " << b << endl;
}
Viva-Voce Questions
Q1.Difference between pass by reference and pass by value?
Ans: Pass by reference passes a pointer to the value. This allows the callee to modify the variable
directly.Pass by value gives a copy of the value to the callee. This allows the callee to modify the value
without modifying the variable. (In other words, the callee simply cannot modify the variable, since it lacks
a reference to it.)
Viva-Voce Questions
Q1. What is function overloading?
Defining several functions with the same name with unique list of parameters is called as function
overloading.
Q2.What is a constructor?
A constructor is the member function of the class which is having the same as the class name and gets
executed automatically as soon as the object for the respective class is created.
void staff::getdata()
{
cout<<"Name:";
gets(name);
cout<<"Code:";
cin>>code;
}
void staff::display()
{
cout<<"Name:"<<name<<endl;
cout<<"Code:"<<code<<endl;
}
void typist::getdata()
{
cout<<"Speed:";
cin>>speed;
}
void typist::display()
{
cout<<"Speed:"<<speed<<endl;
}
int main()
{
typist t;
cout<<"Enter data"<<endl;
t.staff::getdata();
t.getdata();
cout<<endl<<"Display data"<<endl;
t.staff::display();
t.display();
getch();
return 0;
}
Viva-Voce Questions
Q1.List the types of inheritance supported in C++.
Single, Multilevel, Multiple, Hierarchical and Hybrid.
Q3. Data members are the data variables that represent the features or properties of a class.
Member functions are the functions that perform specific tasks in a class.
Member functions are called as methods, and data members are also called as attributes.