0% found this document useful (0 votes)
25 views

Oops Project File

Code questions with answers

Uploaded by

Daizy Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
25 views

Oops Project File

Code questions with answers

Uploaded by

Daizy Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 20
@SRM SRM INSTITUTE OF SCIENCE & TECHNOLOGY Delhi-NCR Campus, Modinagar , Ghaziabad-201204 PRACTICAL FILE SUBJECT TITLE : OBJECT ORIENTED DESIGN AND PROGRAMING SUBJECT CODE : 21CSC101T NAME: Daizy Sharma REGISTRATION NO : RA2311028030008. DEGREE: Btech Cse BRANCH & SECTION: Cse cloud computing A SEMESTER AND YEAR: 2 and 1 SRM INSTITUTE OF SCIENCE & TECHNOLOGY (under section 3 of UGC Act, 1956) BONAFIDE CERTIFICATE It is to be certified that the bonafide record submitted by Daizy Sharma_ & Reg.No. RA2311028030008 of FIRST year & SECOND semester for Bachelor of Technology in Bachelor Degree in theDepartment of Computer Science & Engineering, SRM IST has been done for the course Object Oriented Design & Programing Lab during the academic year of 2023-24. LAB IN CHARGE: HEAD OF DEPARTMENT: EXANINER-1 EXAMINER-2 ©@SRM ‘SRM INSTITUTE OF SCIENCE AND TECHNOLOGY DELHI NCR CAMPUS, MODINAGAR LIST OF EXPERIMENTS Title of Experiments Date | Signature "program for inpuvoutput operators in CH Write a program for data type in CHF Write a program for operators in CH Write a program for decision making in C+¥. Write a program for class and object in CF Write a program for constructor& destructor in CH 1 2 3 4 5 _| Write a program for loops in CH 6 7 8 _ | Write aprogram for operator overloading in C+. Q _| Write a program for function overloading in CH 10 | Write aprogram for inheritance in CH T1 | Write aprogram for fiend function in CHF. 12_| ite @ program for inline function in CH 13 _ | We @PreeFam Tor viral Tunetion in CH ‘ALUE ADDED PROGRAMS Programs Date Signature Write a program for template in C+¥. Write a program for exception handling in C+. Program-1: Write A Program for input/output operators in C++. #include using namespace std: int main { int num; cout << "Enter an integer" cin>> num; // Taking input cout << "The number is: " << num:retum 0; } OUTPU Enteran integer: 70 ‘The number is: 70 Program-2: Write a Program for Data Type in C++. #include using namespace std; int main t intmyNum float myPloatNum = 5.99: double myDoubleNum = 9.98908; char myLetter='D’; string myText = "Hello"; cout< using namespace std; int main { inta, bs 1 b=2; cout<<"a + b=" <<(a +b) << endl; cout << "a -b=" << (a-b) << endl; cout << "a *b="<<(a*b) << endl cout << "a/b =" << (a/b) > number, if (mumber> 0) { cout <<"You entered a positive integer: " << number << endl; else { cout <<"You entered a negati ) return 0; } OUTPUT: integer: " << number << endl; Enteran integer: 4 ‘You entered a positive integer: 4 Enteran integer: 4 You entered a negative integer: 4 Program-5: Write a program for loops in C++. +#include using namespace std; int maing { for (int i= 1; i<=3; +44) { cout <<"Hello World! "<< endl; } return 0; ourpur: HelloWorld! HelloWorld! HelloWorld! Program-6: Write a program for class & objects in C++. include using namespace std: class Rectangle [ private double length; double width: public: Rectangle(double |, double w) : length(!), width(w) {}double area() { return length * width; int main { Rectangle rect(5.0, 3.0); cout << “Area of the rectangle: ” << rectarea() << cendl;retum 0; } OUTPUT: Area of the rectangle: 15 Program-7: Write a program for Constructor & Destructor in C++ ‘include using namespace std; class Z t public’ mw { cout<<"Constructor called”< using namespace sid; class Count { private: int value; public: Count : value(s) {} void operator + ot +values void display() { cout << "Count: "<< value << endl; int main() { Count count; +Heountl; count display(); return 0; Program-9: Write a program for function overloading in C++. ‘inelude using namespace std: void add(int a, intb) fout<< "sum =" << (a+b): void add{double a, double b) , cout << endl << "sum ="<<(a+b): inaing add(10, 2); add(5.3, 62); return 0; Program-10: Write a program for inheritance in C++. +#include > id cout << "Enter the Name:"; cin >> name; we display_p() cout << endl <<"Id: "<< id << "\nName: " << name <> fees 3 void display_s() { display_p0s cout <<"Course: "<< course << "\nFee:" << fee << endl; h int main) Students; sset_s()s sdisplay_s() return 0;} ourrur: Enter the 1d:054 Enter the Name: vaibhay Enter the Course Name: B.tech Enter the Course Fee:300000 Ta: 54 Name: vaibhay Course: B.tech Fee: 300000 Program 11: Write a program for friend function in C++ include using namespace std; class Distance private: int meter; fiend int addFive(Distance); public: Distance(): meter(0) {} } int addFive( Distance d) {d.meter += 5. return d.meter; } int main { Distance D: cout << "Distance: " << addFive(D);retum 0; Output; Distance: 5 Program12: Write a program for inline function +#include using namespace std class operation { inta, b,add, sub, mul; float div; public: void get(): void sum(); void difference(): void product): void division() inline void operation =:get() cout << "Enter first value:"scin >> a; cout< “Enter second value:"; b; inline void operation ::sum() { add =a+b; cout << "Addition of two numbers: " using namespace sid; class, public void show() cout << "Base class" << std:sendl; class derived! : public base public void show() cout << "Derived class 1" << std::endl: bh class derived? : public base { public void show() ‘ std::cout << "Derived class 2" << std::endl; int main) { base *b; derived! dl: derived? 42: beadl; b>show(: b=ad2; boshow()s return 0; Base class Base class 2. Pure virtual function#include using namespace stds # Abstract class class Shape public virtual float caleulateArea() = 0; // pure virtual function. Es class Square - public Shape { float a; public: ‘Square(float 1) t asl; float calculateArea() t reurnata; class Cirele : public Shape { float r; public Circle(float x) { rex: float calculaterea() return 3.14* rr; class Rectangle : public Shape float 1; float b; public: Rectangle (float x, float y) { float calculateArea() { return Ib int main() { Shape *shape; Square s(3.4); Rectangle 15.6); Circle e(7.8); shape =&s; intal =shape>calculateArea(): shape = &r; int a2 = shape->caleulateArea(); shape = int a3 = shape--caleulateArea(); cout << "Area of the square is" < using namespace stds template T myMax(T x, T y) return (> y) PX 2y5 int main) { cout << myMax('g Nc endl; return 0; Program-2: Write a program for exception handling in C++. #include using namespace std: int main() { double numerator, denominator, divide; cout << "Enter numerator: " cin >> numerator; cout << "Enter denominator: "; cin >> denon nator: wry if (denominator throw 0; divide = numerator / denominator; cout << numerator <<" /" << denominator <<" =" << divide << endl; catch (int num_exception) { cout << "Enror: Cannot divide by" << num_exception << endl; return 0; Output: Enter numerator: 2 Enter denominator: 4 2/4205

You might also like