×
You can use excuses to convince others, but how will you convince yourself?
--Your friends at LectureNotes
Close

Object Oriented Programming Using Cpp

by Nallamalli SushmaNallamalli Sushma
Type: PracticalInstitute: ACET/JNTUK Specialization: Computer Science EngineeringViews: 94Uploaded: 2 months ago

Share it with your friends

Suggested Materials

Leave your Comments

Contributors

Nallamalli Sushma
Nallamalli Sushma
OBJECT-ORIENTED PROGRAMMING LAB MANUAL I Year - II Semester OBJECT-ORIENTED PROGRAMMING LAB Programming: Exercise – 1 (Basics) Write a Simple Program on printing “Hello World” and “Hello Name” where name is the input from the user a) Convert any two programs that are written in C into C++ b) Write a description of using g++ (150 Words) Exercise – 2 (Expressions Control Flow) a) Write a Program that computes the simple interest and compound interest payable on principal amount (in Rs.) of loan borrowed by the customer from a bank for a given r period of time (in years) at specific rate of interest. Further determine whether the bank will benefit by charging simple interest or compound interest. b) Write a Program to calculate the fare for the passengers travelling in a bus. When a Passenger enters the bus, the conductor asks “What distance will you travel?” On knowing distance from passenger (as an approximate integer), the conductor mentions the fare to the passenger according to following criteria. Exercise – 3 (Variables, Scope, Allocation) a) Write a program to implement call by value and call by reference using reference variable. b) Write a program to illustrate scope resolution, new and delete Operators. (Dynamic Memory Allocation) c) Write a program to illustrate Storage classes d) Write a program to illustrate Enumerations Exercises –4 (Functions) Write a program illustrating Inline Functions a) Write a program illustrate function overloading. Write 2 overloading functions for power. b) Write a program illustrate the use of default arguments for simple interest function. Exercise -5 (Functions –Exercise Continued) a) Write a program to illustrate function overloading. Write 2 overloading functions for adding two numbers. b) Write a program illustrate function template for power of a number. c) Write a program to illustrate function template for swapping of two numbers. Exercise -6 (Classes Objects) Create a Distance class with: • feet and inches as data members • member function to input distance • member function to output distance • member function to add two distance objects a). Write a main function to create objects of DISTANCE class. Input two distances and output the sum. b). Write a C++ Program to illustrate the use of Constructors and Destructors (use the above program.) c) Write a program for illustrating function overloading in adding the distance between objects (use the above problem) d). Write a C++ program demonstrating a Bank Account with necessary methods and variables Exercise – 7 (Access) a) Write a program for illustrating Access Specifiers public, private, protected b) Write a program implementing Friend Function c) Write a program to illustrate this pointer d) Write a Program to illustrate pointer to a class Exercise -8 (Operator Overloading) DMSSVH COLLEGE OF ENGINEERING 1
OBJECT-ORIENTED PROGRAMMING LAB MANUAL a). Write a program to Overload Unary, and Binary Operators as Member Function, and Non Member Function. i. Unary operator as member function ii. Binary operator as nonmember function b). Write a c ++ program to implement the overloading assignment = operator c).Write a case study on Overloading Operators and Overloading Functions (150 Words) Exercise -9 (Inheritance) a) Write C++ Programs and incorporating various forms of Inheritance i) Single Inheritance ii) Hierarchical Inheritance iii) Multiple Inheritances iv) Multi-level inheritance v) Hybrid inheritance b) Write a program to show Virtual Base Class c) Write a case study on using virtual classes (150 Words) Exercise-10 (Inheritance –Continued) a) Write a Program in C++ to illustrate the order of execution of constructors and destructors in inheritance. b) Write a Program to show how constructors are invoked in derived class Exercise -11 (Polymorphism) a) Write a program to illustrate runtime polymorphism b) Write a program to illustrate this pointer c) Write a program illustrates pure virtual function and calculate the area of different shapes by using abstract class. d) Write a case study on virtual functions (150 Words) Exercise -12(Templates) a) Write a C++ Program to illustrate template class b) Write a Program to illustrate class templates with multiple parameters c) Write a Program to illustrate member function templates Exercise -13 (Exception Handling) a) Write a Program for Exception Handling Divide by zero b) Write a Program to rethrow an Exception Exercise -14 (STL) a) Write a Program to implement List and List Operations b) Write a Program to implementVector andVector Operations Exercise -15 (STLContinued) a) Write a Program to implement Deque and Deque Operations b) Write a Program to implement Map and Map Operations DMSSVH COLLEGE OF ENGINEERING 2
OBJECT-ORIENTED PROGRAMMING LAB MANUAL Exercise – 1 (Basics) Aim: Write a Simple Program on printing “Hello World” and “Hello Name” where name is the input from the user Source Code(hello.cpp) #include <iostream> using namespace std; int main() { char name[25]; cout<<"Hello World\n"; cout<<"Enter your name:"; cin>>name; cout<<"Hello "<<name<<endl; return 0; } Output: csestaff@cselab2-01:~$ g++ hello.cpp csestaff@cselab2-01:~$ ./a.out Hello World Enter your name:Vijaya Hello Vijaya a) Convert any two programs that are written in C into C++ Aim(1a): Write a C++ program to check whether the given number is even or odd. Source Code (even.cpp) #include <iostream> using namespace std; int main() { int n; cout << "Enter a number: "; cin >> n; if(n%2 == 0) cout << n << " is an EVEN number"<<endl; else cout << n << " is an ODD number"<<endl; return 0; } Output: csestaff@cselab2-01:~$ g++ even.cpp csestaff@cselab2-01:~$ ./a.out DMSSVH COLLEGE OF ENGINEERING 3
OBJECT-ORIENTED PROGRAMMING LAB MANUAL Enter a number: 12 12 is an EVEN number csestaff@cselab2-01:~$ ./a.out Enter a number: 5 5 is an ODD number Aim(1a): Write a C++ program to check whether the given number is Armstrong or not. Source Code (armstrong.cpp) #include <iostream> using namespace std; int main() { int n, m, rem, sum = 0; cout << "Enter a positive integer: "; cin >> n; m = n; while( m != 0) { rem = m % 10; sum = sum +(rem * rem * rem); m = m/ 10; } if(sum==n) cout << n << " is an Armstrong Number\n"; else cout << n<< " is not an Armstrong Number\n"; return 0; } Ouput: csestaff@cselab2-01:~$ g++ armstrong.cpp csestaff@cselab2-01:~$ ./a.out Enter a positive integer: 153 153 is an Armstrong Number csestaff@cselab2-01:~$ ./a.out Enter a positive integer: 122 122 is not an Armstrong Number Exercise – 2 (Expressions Control Flow) Aim(2a): Write a Program that computes the simple interest and compound interest payable on principal_amount(inRs.) of loan borrowed by the customer from a bank for a give r period of time (in years) at specific rate of interest. Further determine whether the bank will benefit by charging simple interest or compound interest. Source Code (interest.cpp) DMSSVH COLLEGE OF ENGINEERING 4

Lecture Notes