R20CSE21L3 C Programming Lab
R20CSE21L3 C Programming Lab
HANDOUT
II Year I Semester
DEPARTMENT OF COMPUTER
SCIENCE AND ENGINEERING
ACADEMIC YEAR 2022-2023
SRI INDU COLLEGE OF ENGINEERING & TECHNOLOGY
(An Autonomous Institution under UGC, New Delhi)
(Permanently Affiliated to JNTUH, Approved by AICTE, New Delhi and Accredited by NBA, NAAC)
Sheriguda Village, Ibrahimpatnam Mandal, Ranga Reddy Dist. – 501 510
IM3: Contribute to the economic and technological development of the region, state and
nation.
SRI INDU COLLEGE OF ENGINEERING & TECHNOLOGY
(An Autonomous Institution under UGC, New Delhi)
(Permanently Affiliated to JNTUH, Approved by AICTE, New Delhi and Accredited by NBA, NAAC)
Sheriguda Village, Ibrahimpatnam Mandal, Ranga Reddy Dist. – 501 510
To be a technologically adaptive centre for computing by grooming the students as top notch
professionals.
DM2: To provide an environment that enables overall development of all the stakeholders.
DM3: To impart training on emerging technologies like Data Analytics, Artificial Intelligence
and Internet Of Things.
Industrial Skills Ability: Design, develop and test software systems for world-
PSO2 wide network of computers to provide solutions to real world
problems.
Program Outcomes(PO’s)
Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
PO5 engineering and IT tools including prediction and modeling to complex engineering activities
with an understanding of the limitations.
The engineer and society: Apply reasoning informed by the contextual knowledge to assess
PO6 societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to
the professional engineering practice.
Environment and sustainability: Understand the impact of the professional engineering
PO7 solutions in societal and environmental contexts, and demonstrate the knowledge of, and
need for sustainable development.
Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
PO8 norms of the engineering practice.
Individual and team work: Function effectively as an individual, and as a member or leader
PO9 in diverse teams, and in multidisciplinary settings.
Communication: Communicate effectively on complex engineering activities with the
PO10 engineering community and with society at large, such as, being able to comprehend and
write effective reports and design documentation, make effective presentations, and give and
receive clear instructions.
Project management and finance: Demonstrate knowledge and understanding of the
PO11 engineering and management principles and apply these to one’s own work, as a member and
leader in a team, to manage projects and in multidisciplinary environments.
Life-long learning: Recognize the need for, and have the preparation and ability to engage in
PO12 independent and life-long learning in the broadest context of technological change.
COURSE OUTCOMES (CO’s)
Academic Year: 2022-23
Apply virtual and pure virtual function & complex program situations(Apply)
C21L3.3
Apply fundamental algorithmic problems including type
C21L3.4 casting, inheritance, andpolymorphism. (Apply)
PO
CO
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
3 2 3 3 1 1 - - - - 3 1
C21L3.1
3 3 3 3 - - - - - - - 1
C21L3.2
3 3 3 3 - - - - 1 - 1 1
C21L3.3
3 2 3 2 - 1 - - - - - 1
C21L3.4
C21L3.5 3 3 3 3 - - - - 1 - - 2
3 3 3 3 - - - - - - - 1
C21L3.6
3 2.6 3 2.6 - 1 - - 1 - 3 1.5
DAYS
SUNDAY NOVEMBER ‘22
DECEMBER
MONDAY 1 FEBRUARY’23
‘22
SEPTEMBER‘2
TUESDAY 2 1
2
PRACTICAL
WEDNESDAY 3 1 2
EXAM
PRACTICAL
THURSDAY 1 OCTOBER ‘22 4 2 3
EXAM
Bathukamm
a PRACTICAL
FRIDAY 2 1 5 3 JANUARY’23 4
Celebration EXAM
s
Gandhi NEW YEAR/
SATURDAY 3 2 Jayanti/ 6 HOLIDAY 4 HOLIDAY 1 5 HOLIDAY
HOLIDAY
HOLIDAY
DASARA PRACTICAL
SUNDAY 4 HOLIDAY 3 7 5 2 6
HOLIDAYS EXAM
DASARA GURUNAN
PRACTICAL
MONDAY 5 4 HOLIDAYS 8 AK 6 3 7
EXAM
JAYANTHI
DASARA PRACTICAL
TUESDAY 6 5 9 7 4 8
HOLIDAYS EXAM
DASARA PRACTICAL
WEDNESDAY 7 6 10 8 5 9
HOLIDAYS EXAM
DASARA PRACTICAL
THURSDAY 8 7 11 9 6 10
HOLIDAYS EXAM
DASARA PRACTICAL
FRIDAY 9 8 12 10 7 11
HOLIDAYS EXAM
SATURDAY10 9 HOLIDAY 13 HOLIDAY 11 HOLIDAY 8 H OLIDAY 12 HOLIDAY
HOD/CSE
CALENDAR INCHARGE DEAN PRINCIPAL
SRI INDU COLLEGE OF ENGINEERING & TECHNOLOGY
(An Autonomous Institution under UGC, New Delhi)
LIST OF EXPERIMENTS
1. Write a C++ Program to display Names, Roll No., and grades of 3 students who have appeared
in the examination. Declare the class of name, Roll No. and grade. Create an array of class
objects. Read and display the contents of the array.
2. Write a C++ program to declare Struct. Initialize and display contents of member variables.
3. Write a C++ program to declare a class. Declare pointer to class. Initialize and display the
contents of the class member.
4. Given that an EMPLOYEE class contains following members: data members: Employee
number, Employee name, Basic, DA, IT, Net Salary and print data members.
5. Write a C++ program to read the data of N employee and compute Net salary of each employee
(DA=52% of Basic and Income Tax (IT) =30% of the gross salary).
6. Write a C++ to illustrate the concepts of console I/O operations.
7. Write a C++ program to use scope resolution operator. Display the various values of the same
variables declared at different scope levels.
8. Write a C++ program to allocate memory using new operator.
9. Write a C++ program to create multilevel inheritance. (Hint: Classes A1, A2, A3)
10. Write a C++ program to create an array of pointers. Invoke functions using array objects.
11. Write a C++ program to use pointer for both base and derived classes and call the member
function. Use Virtual keyword.
SRI INDU COLLEGE OF ENGG & TECH
Prepared on
LAB PLAN Rev1:
(Regulation
:R20) Page: 1 of 4
Department of Computer Science and Engineering
(R20CSE21L3)
Sub. Code & Object Oriented Programming using C++ LAB
Title
Academic Year: Year/Sem./Sect
2022-23 ion II/I/A&B&C&D
1. DR.N.SADASHIVAM
(PROFESSOR),
2. A.SUDHEER ASST.PROF,
Faculty Name & 3. G.AKILA ASST.PROF,
Designation 4. K.KRISHNA ASST.PROF
Lab Plan
2022-23 II Year –I Semester CSE
No. of weeks
S No Topics
1. 1 Write a C++ Program to display Names, Roll No., and grades of 3 students 1
who have appearedin the examination. Declare the class of name, Roll No.
and grade. Create an array of class objects. Read and display the contents of
the array.
2. 2 Write a C++ program to declare Struct. Initialize and display contents of member 1
variables.
4. 2 1
5. 1 Write a C++ program to read the data of N employee and compute Net salary 1
of each employee(DA=52% of Basic and Income Tax (IT) =30% of the gross
salary).
7. 1 Write a C++ program to use scope resolution operator. Display the various 1
values of the samevariables declared at different scope levels.
9. 2 Write a C++ program to create multilevel inheritance. (Hint: Classes A1, A2, 1
A3)
10. 2 Write a C++ program to create an array of pointers. Invoke functions using array 1
objects.
11. Write a C++ program to use pointer for both base and derived classes and call 1
the memberfunction. Use Virtual keyword.
Object Oriented Programming using C++ Lab Manual
(Subject Code: R20CSE21L3)
Computer Science &Engineering
LabManual
C++Programming
1. Write a C++ Program to display Names, Roll No., and grades of 3 students who have
appeared in the examination. Declare the class of name, Roll No. and grade. Create an array
of class objects. Read and display the contents of thearray.
2. Write a C++ program to declare Struct. Initialize and display contents of membervariables.
3. Write a C++ program to declare a class. Declare pointer to class. Initialize and displaythe
contents of the classmember.
4. Given that an EMPLOYEE class contains following members: data members:Employee
number, Employee name, Basic, DA, IT, Net Salary and print datamembers.
5. Write a C++ program to read the data of N employee and compute Net salary ofeach
employee (DA=52% of Basic and Income Tax (IT) =30% of the grosssalary).
6. Write a C++ to illustrate the concepts of console I/Ooperations.
7. Write a C++ program to use scope resolution operator. Display the various values of thesame
variables declared at different scopelevels.
8. Write a C++ program to allocate memory using newoperator.
9. Write a C++ program to create multilevel inheritance. (Hint: Classes A1, A2,A3)
10. Write a C++ program to create an array of pointers. Invoke functions using arrayobjects.
11. Write a C++ program to use pointer for both base and derived classes and call themember
function. Use Virtualkeyword
PROGRAMS
Week 1.
Aim:Write a C++ Program to display Names, Roll No., and grades of 3 students who have
appeared in the examination. Declare the class of name, Roll No. and grade. Create an
array of class objects. Read and display the contents of the array.
Source Code:
namespace std;
class student {
public:
charname[50];
int roll;
chargrade;
} s[3];
int main() {
cout <<"Enterinformation of students:" << endl;
// storinginformation
for(int i = 0; i <3; ++i) {
s[i].roll =i+1;
cout <<"For roll number" <<s[i].roll <<"," <<endl;
// Displayinginformation
for(int i = 0; i <3; ++i) {
cout <<"\nRoll number: " <<i+1 <<endl;
cout <<"Name: " <<s[i].name <<endl; cout
<<"Grade: " <<s[i].grade <<endl;
}
return 0;
}
Output:
Week 2:
Aim:Write a C++ program to declare Struct. Initialize and display contents of member variables.
Source Code:
struct Person
{
charname[50];
int age;
float salary;
};
int main()
{
Personp1;
return 0;
}
Output:
Week 3:
Aim:Write a C++ program to declare a class. Declare pointer to class. Initialize and
display the contents of the class member.
Sourcecode:
#include <iostream>
using namespacestd;
classData
{
public:
inta;
void print()
{
cout <<"\n" <<"Value of 'a' is "<< a <<"\n";
}
};
int main()
{
Data d, *dp;
dp=&d; // pointer toobject
d.*ptr=10;
d.print();
dp->*ptr=20;
dp->print();
return 0;
}
Output:
Week 4:
Source code:
#include <iostream>
#include<conio.h>
classemployee
{
int emp_number;
char
emp_name[20];f
loat emp_basic;
floatsal;
floatemp_da;
floatemp_net_sal;
floatemp_it;
public:
void get_details(int i);
void find_net_sal();
voidshow_emp_details();
};
intmain() {
employeeemp[10];
int i,num;
for(i=0;i<num;i++)
emp[i].get_details(i);
for(i=0;i<num;i++)
emp[i].show_emp_details();
getch();
return 0;
}
Output:
Week 5:
Aim:Write a C++ program to read the data of N employee and compute Net salary of each
employee (DA=52% of Basic and Income Tax (IT) =30% of the gross salary).
Source code:
#include <iostream>
#include<conio.h>
class employee {
int emp_num;
char
emp_name[20];f
loat emp_basic;
floatsal;
floatemp_da;
float net_sal;
float emp_it;
public:
void get_details(int i);
void find_net_sal();
voidshow_emp_details();
};
cout<<"\nEnternumberofemployeedetails:";
cin>>num;
for(i=0;i<num;i++)
emp[i].get_details(i);
for(i=0;i<num;i++)
emp[i].find_net_sal();
for(i=0;i<num;i++)
emp[i].show_emp_details();
getch();
return 0;
}
Output:
Week6:
Source code:
#include <iostream>
#include<conio.h>
int main() {
char c;
cout<<"\nEnteranycharactervalue:";
c=cin.get();
return 0;
}
Output:
#include <iostream>
#include<conio.h>
int main() {
cout<<"\nEnteranyname:";
charc[10];
cin.getline(c,10); //It takes 10 charcters as input;
cout.write(c,9); //It reads only 9 character from buffer c;
cout<<"\n";
return 0;
}
Output:
#include <iostream>
#include<conio.h>
int main() {
int num; char
ch; stringstr;
cout<<"\nEnterNumber:";
cin>>num; //Inputs a variable;
cout<<"Enter Character: ";
cin>>ch; //Inputs a character;
cout<<"Enter String: "; cin>>str;
//Inputs astring;
cout<<endl<<"Youhaveentered:\nNumber:"<<num<<"\nCharacter:"
<<ch<<"\nString:"<<str<<endl;
return 0;
Output:
Week 7:
Write a C++ program to use scope resolution operator. Display the various values of the same
variables declared at different scope levels.
Source code:
#include <iostream>
#include<conio.h>
int x;
int main() {
int x = 10; // Local x
cout <<"\nValue of global x is " <<::x; cout
<<"\nValue of local x is " << x<<endl;
return 0;
Output:
Week 8:
Source code:
#include <iostream>
#include<conio.h>
int main() {
return 0;
}
Output:
Week 9:
Write a C++ program to create multilevel inheritance. (Hint: Classes A1, A2, A3)
Source code:
#include <iostream>
#include<conio.h>
public:
int x;
void getdata() {
cout <<"Enter value of x="; cin >>x;
}
};
class derive1 : public base // derived class from base class
{
public:
int y;
voidreaddata()
{
cout <<"\nEnter value of y= "; cin >>y;
}
};
class derive2 :publicderive1 // derived from classderive1
{
private:
int z;
public:
void indata() {
cout <<"\nEnter value of z= "; cin >>z;
}
void product() {
cout<<"\nProduct="<<x*y*z<<endl;
}
};
int main() {
derive2a; //object of derived class
a.getdata();
a.readdata();
a.indata();
a.product();
return 0;
}
Output:
Viva Questions:
1. What is Inheritance?
2.Types ofinheritance?
Week 10:
Write a C++ program to create an array of pointers. Invoke functions using array objects.
Source code:
#include
<iostream>#include
<string>
classStudent
{
stringname; int
marks; public:
voidgetName()
{
getline( cin, name);
}
voidgetMarks()
{
cin >> marks;
}
void displayInfo()
{
cout <<"Name : " << name <<endl; cout
<<"Marks : " << marks <<endl;
}
};
int main()
{
Student st[5].*ptr;
ptr=&st;
for( int i=0; i<5; i++ )
{
cout <<"Student " <<i + 1 << endl; cout
<<"Enter name" << endl;
st[i]->getName();
cout <<"Enter marks" << endl;
st[i]->getMarks();
}
Write a C++ program to use pointer for both base and derived classes and call the member
function. Use Virtual keyword.
Source code:
class Weapon{
public:
virtual void features() { cout <<"Loading weapon features.\n"; }
};
public:
void features() {
this->Weapon::features();
cout <<"Loading gun features.\n";
}
};
class Loader {
public:
void loadFeatures(Weapon *weapon) {
weapon->features();
}
};
int main() {
Loader *l = new Loader;
Weapon*w;
Bomb b;
Gun g; w
=&b;
l->loadFeatures(w);
w =&g;
l->loadFeatures(w);
return 0;
}
Output: