├── GroupA_Practical1.cpp ├── GroupA_Practical2.cpp ├── GroupA_Practical3.cpp ├── GroupB_Practical4.cpp ├── GroupB_Practical5.cpp ├── GroupC_Practical6.cpp ├── GroupC_Practical7.cpp └── README.md /GroupA_Practical1.cpp: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Implement a class Complex which represents the Complex Number data type. Implement the following 4 | 1. Constructor (including a default constructor which creates the complex number 0+0i). 5 | 2. Overload operator+ to add two complex numbers. 6 | 3. Overload operator* to multiply two complex numbers. 7 | 4. Overload operators << and >> to print and read Complex Numbers 8 | */ 9 | 10 | 11 | # include 12 | using namespace std; 13 | class Complex //decaring Class Complex 14 | { 15 | double real; 16 | double img; 17 | public: 18 | Complex(); // Default Constructor 19 | friend istream & operator >> (istream &, Complex &); // Input 20 | friend ostream & operator << (ostream &, const Complex &); // Output 21 | Complex operator + (Complex); // Addition 22 | Complex operator * (Complex); // Multiplication 23 | }; 24 | Complex::Complex() // Default Constructor 25 | { 26 | real = 0; 27 | img = 0; 28 | } 29 | istream & operator >> (istream &, Complex & i) 30 | { 31 | cin >> i.real >> i.img; 32 | return cin; 33 | } 34 | ostream & operator << (ostream &, const Complex & d) 35 | { 36 | cout << d.real << " + " << d.img << "i" << endl; 37 | return cout; 38 | } 39 | Complex Complex::operator + (Complex c1) // Overloading + operator 40 | { 41 | Complex temp; 42 | temp.real = real + c1.real; 43 | temp.img = img + c1.img; 44 | return temp; 45 | } 46 | Complex Complex::operator * (Complex c2) // Overloading * Operator 47 | { 48 | Complex tmp; 49 | tmp.real = real * c2.real - img * c2.img; 50 | tmp.img = real * c2.img + img * c2.real; 51 | return tmp; 52 | } 53 | int main() 54 | { 55 | Complex C1, C2, C3, C4; 56 | int flag = 1; 57 | char b; 58 | while (flag == 1) 59 | { 60 | cout << "Enter Real and Imaginary part of the Complex Number 1 : \n"; 61 | cin >> C1; 62 | cout << "Enter Real and Imaginary part of the Complex Number 2 : \n"; 63 | cin >> C2; 64 | int f = 1; 65 | while (f == 1) 66 | { 67 | cout << "Complex Number 1 : " << C1 << endl; 68 | cout << "Complex Number 2 : " << C2 << endl; 69 | cout << "**********MENU**********" << endl; 70 | cout << "1. Addition of Complex Numbers" << endl; 71 | cout << "2. Multiplication of Complex Numbers" << endl; 72 | cout << "3. Exit\n"; 73 | int a; 74 | cout << "Enter your choice from above MENU (1 to 3) : "; 75 | cin >> a; 76 | if (a == 1) 77 | { 78 | C3 = C1+C2; 79 | cout << "Addition : " << C3 << endl; 80 | cout << "Do you wan to perform another operation (y/n) : \n"; 81 | cin >> b; 82 | if (b == 'y' | | b == 'Y') 83 | { 84 | f=1; 85 | } 86 | else 87 | { 88 | cout << "Thanks for using this program!!\n"; 89 | flag=0; 90 | f=0; 91 | } 92 | } 93 | else if (a == 2) 94 | { 95 | C4 = C1 * C2; 96 | cout << "Multiplication : " << C4 << endl; 97 | cout << "Do you wan to perform another operation (y/n) : \n"; 98 | cin >> b; 99 | if (b == 'y' | | b == 'Y') 100 | { 101 | f=1; 102 | } 103 | else 104 | { 105 | cout << "Thanks for using this program!!\n"; 106 | flag=0; 107 | f=0; 108 | } 109 | } 110 | else 111 | { 112 | cout << "Thanks for using this program!!\n"; 113 | flag=0; 114 | f=0; 115 | } 116 | } 117 | } 118 | return 0; 119 | } 120 | -------------------------------------------------------------------------------- /GroupA_Practical2.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Experiment Number 2 : Develop a program in C++ to create a database of 3 | student’s information system 4 | containing the following information: Name, Roll number, Class, Division, 5 | Date of Birth, Blood group, 6 | Contactaddress, Telephone number, Driving license no. and other. Construct 7 | the database with 8 | suitable member functions. Make use of constructor, default constructor, 9 | copy constructor, 10 | destructor, static member functions, friend class, this pointer, inline 11 | code and dynamic 12 | memory allocation operators-new and delete as well as exception handling. 13 | */ 14 | 15 | 16 | 17 | #include 18 | #include 19 | using namespace std; 20 | 21 | class StudData; 22 | 23 | class Student{ 24 | string name; 25 | int roll_no; 26 | string cls; 27 | char* division; 28 | string dob; 29 | char* bloodgroup; 30 | static int count; 31 | 32 | public: 33 | 34 | Student() // Default Constructor 35 | { 36 | name=""; 37 | roll_no=0; 38 | cls=""; 39 | division=new char; 40 | dob="dd/mm/yyyy"; 41 | bloodgroup=new char[4]; 42 | } 43 | 44 | ~Student() 45 | { 46 | delete division; 47 | delete[] bloodgroup; 48 | } 49 | 50 | static int getCount() 51 | { 52 | return count; 53 | } 54 | 55 | void getData(StudData*); 56 | void dispData(StudData*); 57 | }; 58 | 59 | class StudData{ 60 | string caddress; 61 | long int* telno; 62 | long int* dlno; 63 | friend class Student; 64 | 65 | public: 66 | 67 | StudData() 68 | { 69 | caddress=""; 70 | telno=new long; 71 | dlno=new long; 72 | } 73 | 74 | ~StudData() 75 | { 76 | delete telno; 77 | delete dlno; 78 | } 79 | 80 | void getStudData() 81 | { 82 | cout<<"Enter Contact Address : "; 83 | cin.get(); 84 | getline(cin,caddress); 85 | cout<<"Enter Telephone Number : "; 86 | cin>>*telno; 87 | cout<<"Enter Driving License Number : "; 88 | cin>>*dlno; 89 | } 90 | 91 | void dispStudData() 92 | { 93 | cout<<"Contact Address : "<>roll_no; 105 | cout<<"Enter Class : "; 106 | cin.get(); 107 | getline(cin,cls); 108 | cout<<"Enter Division : "; 109 | cin>>division; 110 | cout<<"Enter Date of Birth : "; 111 | cin.get(); 112 | getline(cin,dob); 113 | cout<<"Enter Blood Group : "; 114 | cin>>bloodgroup; 115 | st->getStudData(); 116 | count++; 117 | } 118 | 119 | inline void Student::dispData(StudData* st1) 120 | { 121 | cout<<"Student Name : "<dispStudData(); 128 | } 129 | 130 | int Student::count; 131 | 132 | int main() 133 | { 134 | Student* stud1[100]; 135 | StudData* stud2[100]; 136 | int n=0; 137 | char ch; 138 | 139 | do 140 | { 141 | stud1[n]=new Student; 142 | stud2[n]=new StudData; 143 | stud1[n]->getData(stud2[n]); 144 | n++; 145 | cout<<"Do you want to add another student (y/n) : "; 146 | cin>>ch; 147 | cin.get(); 148 | } while (ch=='y' || ch=='Y'); 149 | 150 | for(int i=0;idispData(stud2[i]); 154 | } 155 | 156 | cout<<"---------------------------------------------------------------"< 17 | # include 18 | using namespace std; 19 | class publication // declaring class Publication 20 | { 21 | private: 22 | string title; 23 | float price; 24 | public: 25 | void add() 26 | { 27 | cout << "\nEnter the Publication information : " << endl; 28 | cout << "Enter Title of the Publication : "; 29 | cin.ignore(); 30 | getline(cin, title); 31 | cout << "Enter Price of Publication : "; 32 | cin >> price; 33 | } 34 | void display() 35 | { 36 | cout << "\n--------------------------------------------------"; 37 | cout << "\nTitle of Publication : " << title; 38 | cout << "\nPublication Price : " << price; 39 | } 40 | }; 41 | class book : public publication // declaring class book which inherits class publication in public mode. 42 | { 43 | private: 44 | int page_count; 45 | public: 46 | void add_book() 47 | { 48 | try 49 | { 50 | add(); 51 | cout << "Enter Page Count of Book : "; 52 | cin >> page_count; 53 | if (page_count <= 0) 54 | { 55 | throw page_count; 56 | } 57 | } 58 | catch(...) 59 | { 60 | cout << "\nInvalid Page Count!!!"; 61 | page_count = 0; 62 | } 63 | } 64 | void display_book() 65 | { 66 | display(); 67 | cout << "\nPage Count : " << 68 | page_count; 69 | cout << "\n--------------------------------------------------\n"; 70 | } 71 | }; 72 | class tape : public publication // declaring class tape which inherits class publication in public mode 73 | { 74 | private: 75 | float play_time; 76 | public: 77 | void add_tape() 78 | { 79 | try 80 | { 81 | add(); 82 | cout << "Enter Play Duration of the Tape : "; 83 | cin >> play_time; 84 | if (play_time <= 0) 85 | throw play_time; 86 | } 87 | catch(...) 88 | { 89 | cout << "\nInvalid Play Time!!!"; 90 | play_time = 0; 91 | } 92 | } 93 | void display_tape() 94 | { 95 | display(); 96 | cout << "\nPlay Time : " << 97 | play_time << " min"; 98 | cout << "\n--------------------------------------------------\n"; 99 | } 100 | }; 101 | int main() 102 | { 103 | book b1[10]; // object of class book 104 | tape t1[10]; // object of class tape 105 | int ch, b_count = 0, t_count = 0; 106 | do 107 | { 108 | cout << "\n* * * * * PUBLICATION DATABASE SYSTEM * * * * *"; 109 | cout << "\n--------------------MENU-----------------------"; 110 | cout << "\n1. Add Information to Books"; 111 | cout << "\n2. Add Information to Tapes"; 112 | cout << "\n3. Display Books Information"; 113 | cout << "\n4. Display Tapes Information"; 114 | cout << "\n5. Exit"; 115 | cout << "\n\nEnter your choice : "; 116 | cin >> ch; 117 | switch(ch) 118 | { 119 | case 1: 120 | b1[b_count].add_book(); 121 | b_count + +; 122 | break; 123 | case 2: 124 | t1[t_count].add_tape(); 125 | t_count + +; 126 | break; 127 | case 3: 128 | cout << "\n* * * * BOOK PUBLICATION DATABASE SYSTEM * * * *"; 129 | for (int j=0;j < b_count;j++) 130 | { 131 | b1[j].display_book(); 132 | } 133 | break; 134 | case 4: 135 | cout << "\n* * * * TAPE PUBLICATION DATABASE SYSTEM * * * *"; 136 | for (int j=0;j < t_count;j++) 137 | { 138 | t1[j].display_tape(); 139 | } 140 | break; 141 | case 5: 142 | exit(0); 143 | } 144 | }while (ch != 5); 145 | return 0; 146 | } 147 | -------------------------------------------------------------------------------- /GroupB_Practical4.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Write a C++ program that creates an output file, writes information to it, closes the file, open it again as an input file and read the information from the file. 3 | */ 4 | 5 | #include 6 | #include 7 | using namespace std; 8 | class Employee // declaring class employee 9 | { 10 | string Name; 11 | int ID; 12 | double salary; 13 | public: 14 | void accept() 15 | { 16 | cout<<"\n Name : "; 17 | cin.ignore(); 18 | getline(cin,Name); 19 | cout<<"\n Id : "; 20 | cin>>ID; 21 | cout<<"\n Salary : "; 22 | cin>>salary; 23 | } 24 | void display() 25 | { 26 | cout<<"\n Name : "<>n; 41 | for(i=0;i 7 | using namespace std; 8 | int n; 9 | #define size 10 10 | template 11 | void sel(T A[size]) 12 | { 13 | int i,j,min; 14 | T temp; 15 | for(i=0;i>ch; 49 | 50 | switch(ch) 51 | { 52 | case 1: 53 | cout<<"\nEnter total no of int elements:"; 54 | cin>>n; 55 | cout<<"\nEnter int elements:"; 56 | for(i=0;i>A[i]; 59 | } 60 | sel(A); 61 | break; 62 | 63 | case 2: 64 | cout<<"\nEnter total no of float elements:"; 65 | cin>>n; 66 | cout<<"\nEnter float elements:"; 67 | for(i=0;i>B[i]; 70 | } 71 | sel(B); 72 | break; 73 | 74 | case 3: 75 | exit(0); 76 | } 77 | }while(ch!=3); 78 | 79 | 80 | 81 | return 0; 82 | 83 | } 84 | 85 | -------------------------------------------------------------------------------- /GroupC_Practical6.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Write C++ Program using STL for sorting and searching user defined 3 | records such as item records using vector container. 4 | */ 5 | #include //standard input output stream header file 6 | #include //The STL algorithms are generic because 7 | they can operate on a variety of data structures 8 | #include //The header file for the STL vector library is 9 | vector. 10 | using namespace std; 11 | class Item // creating class Item 12 | { 13 | public: 14 | char name[10]; 15 | int quantity; 16 | int cost; 17 | int code; 18 | bool operator==(const Item& i1) //Boolean operators allow 19 | you to create more complex conditional statements 20 | { 21 | if(code==i1.code) //operator will return 1 if the 22 | comparison is true, or 0 if the comparison is false 23 | return 1; 24 | return 0; 25 | } 26 | bool operator<(const Item& i1) 27 | { 28 | if(code o1; 35 | void print(Item &i1); 36 | void display(); 37 | void insert(); 38 | void search(); 39 | void dlt(); 40 | bool compare(const Item &i1, const Item &i2) 41 | { 42 | //if (i1.name != i2.name) return i1.cost < i2.cost; 43 | return i1.cost < i2.cost; 44 | } 45 | int main() 46 | { 47 | int ch; 48 | do 49 | { 50 | cout<<"\n* * * * * Menu * * * * *"; 51 | cout<<"\n1.Insert"; 52 | cout<<"\n2.Display"; 53 | cout<<"\n3.Search"; 54 | cout<<"\n4.Sort"; 55 | cout<<"\n5.Delete"; 56 | cout<<"\n6.Exit"; 57 | cout<<"\nEnter your choice : "; 58 | cin>>ch; 59 | 60 | switch(ch) 61 | { 62 | case 1: 63 | insert(); 64 | break; 65 | 66 | case 2: 67 | display(); 68 | break; 69 | 70 | case 3: 71 | search(); 72 | break; 73 | 74 | case 4: 75 | sort(o1.begin(),o1.end(),compare); 76 | cout<<"\n\n Sorted on Cost : "; 77 | display(); 78 | break; 79 | 80 | case 5: 81 | dlt(); 82 | break; 83 | 84 | case 6: 85 | exit(0); 86 | } 87 | 88 | }while(ch!=7); 89 | return 0; 90 | } 91 | void insert() 92 | { 93 | Item i1; 94 | cout<<"\nEnter Item Name : "; 95 | cin>>i1.name; 96 | cout<<"\nEnter Item Quantity : "; 97 | cin>>i1.quantity; 98 | cout<<"\nEnter Item Cost : "; 99 | cin>>i1.cost; 100 | cout<<"\nEnter Item Code : "; 101 | cin>>i1.code; 102 | o1.push_back(i1); 103 | } 104 | void display() 105 | { 106 | for_each(o1.begin(),o1.end(),print); 107 | } 108 | void print(Item &i1) 109 | { 110 | cout<<"\n"; 111 | cout<<"\nItem Name : "<::iterator p; 120 | Item i1; 121 | cout<<"\nEnter Item Code to search : "; 122 | cin>>i1.code; 123 | p=find(o1.begin(),o1.end(),i1); 124 | if(p==o1.end()) 125 | { 126 | cout<<"\nNot found!!!"; 127 | } 128 | else 129 | { 130 | cout<<"\nFound!!!"; 131 | } 132 | } 133 | void dlt() 134 | { 135 | vector::iterator p; 136 | Item i1; 137 | cout<<"\nEnter Item Code to delete : "; 138 | cin>>i1.code; 139 | p=find(o1.begin(),o1.end(),i1); 140 | if(p==o1.end()) 141 | { 142 | cout<<"\nNot found!!!"; 143 | } 144 | else 145 | { 146 | o1.erase(p); 147 | cout<<"\nDeleted!!!"; 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /GroupC_Practical7.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | typedef map mapType; 11 | mapType populationMap; 12 | 13 | populationMap.insert(pair("Maharashtra", 125)); 14 | populationMap.insert(pair("Uttar Pradesh", 225)); 15 | populationMap.insert(mapType::value_type("Bihar", 120)); 16 | populationMap.insert(mapType::value_type("West Bengal", 100)); 17 | populationMap.insert(make_pair("Madhya Pradesh", 90)); 18 | populationMap.insert(make_pair("Tamil Nadu", 80)); 19 | populationMap.insert(make_pair("Rajasthan", 78)); 20 | populationMap.insert(make_pair("Andhra Pradesh", 53)); 21 | populationMap.insert(make_pair("Odisha", 47)); 22 | populationMap.insert(make_pair("Kerala", 38)); 23 | populationMap.insert(make_pair("Telangana", 37)); 24 | populationMap.insert(make_pair("Assam", 35)); 25 | populationMap.insert(make_pair("Jharkhand", 38)); 26 | populationMap.insert(make_pair("Karnataka", 68)); 27 | populationMap.insert(make_pair("Gujarat", 70)); 28 | populationMap.insert(make_pair("Punjab", 31)); 29 | populationMap.insert(make_pair("Chhattisgarh", 30)); 30 | populationMap.insert(make_pair("Haryana", 29)); 31 | populationMap.insert(make_pair("UT Delhi", 19)); 32 | populationMap.insert(make_pair("UT Jammu and Kashmir", 14)); 33 | populationMap.insert(make_pair("Uttarakhand", 12)); 34 | populationMap.insert(make_pair("Himachal Pradesh", 8)); 35 | populationMap.insert(make_pair("Tripura", 04)); 36 | populationMap.insert(make_pair("Meghalaya", 4)); 37 | populationMap.insert(make_pair("Manipur[", 3)); 38 | populationMap.insert(make_pair("Nagaland", 2)); 39 | populationMap.insert(make_pair("Goa", 2)); 40 | populationMap.insert(make_pair("Arunachal Pradesh", 2)); 41 | populationMap.insert(make_pair("UT Puducherry", 2)); 42 | populationMap.insert(make_pair("Mizoram", 1)); 43 | populationMap.insert(make_pair("UT Chandigarh", 1)); 44 | populationMap.insert(make_pair("Sikkim", 1)); 45 | populationMap.insert(make_pair("UT Dadra and Nagar Haveli and Daman and Diu", 1)); 46 | populationMap.insert(make_pair("UT Andaman and Nicobar Islands", 1)); 47 | populationMap.insert(make_pair("UT Lakshadweep", 0.0003)); 48 | populationMap.insert(make_pair("UT Ladakh", 0.00006)); 49 | 50 | mapType::iterator iter = --populationMap.end(); 51 | populationMap.erase(iter); 52 | 53 | cout << "Total state and UT of India with Size of populationMap: " << populationMap.size() << '\n'; 54 | 55 | for (iter = populationMap.begin(); iter != populationMap.end(); ++iter) 56 | { 57 | cout << iter->first <<":" << iter->second << " million\n"; 58 | } 59 | 60 | char c; 61 | do 62 | { 63 | string state; 64 | cout<<"\nEnter that state you want to know the population of: "; 65 | cin>>state; 66 | iter = populationMap.find(state); 67 | if( iter != populationMap.end() ) 68 | cout << state <<"'s populations is " 69 | << iter->second << " million\n"; 70 | else 71 | cout << "State is not in populationMap" << '\n'; 72 | 73 | cout<<"Do you wish to continue?(y/n):"; 74 | cin>>c; 75 | }while(c=='y'||c=='Y'); 76 | 77 | populationMap.clear(); 78 | 79 | return 0; 80 | } 81 | 82 | 83 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SPPU-2019-Pattern-SE-COMP-Object-Oriented-Programming-Practicals 2 | 3 | Group A : 4 | 5 | Experiment No. 1 : Implement a class Complex which represents the Complex Number data type. Implement the following 6 | 1. Constructor (including a default constructor which creates the complex number 0+0i). 7 | 2. Overload operator+ to add two complex numbers. 8 | 3. Overload operator* to multiply two complex numbers. 9 | 4. Overload operators << and >> to print and read Complex Numbers. 10 | 11 | Experiment No. 2 : Develop a program in C++ to create a database of student’s information system 12 | containing the following information: Name, Roll number, Class, Division, Date of Birth, Blood group, 13 | Contactaddress, Telephone number, Driving license no. and other. Construct 14 | the database with suitable member functions. Make use of constructor, default constructor, copy constructor, 15 | destructor, static member functions, friend class, this pointer, inline code and dynamic memory allocation operators-new and delete as well as exception handling. 16 | 17 | Experiment No. 3 : Imagine a publishing company which does marketing for book and audiocassette versions. Create a class publication that stores the title (a string) 18 | and price (type float) of a publication.From this class derive two classes: book, which adds a page count(type int), and tape, which adds a playing time in minutes(type float). Write a program that instantiates the book and tape classes, allows user to enter data and displays the data members.If an exception is caught, replace all the data member values with zero values. 19 | 20 | 21 | Group B : 22 | 23 | Experiment No. 4 : Write a C++ program that creates an output file, writes information to it, closes the file, open it again as an input file and read the information from the file. 24 | 25 | Experiment No. 5 : Write a function template for selection sort that inputs, sorts and outputs an integer array and a float array. 26 | 27 | 28 | Group C : 29 | 30 | Experiment No. 6 : Write C++ program using STL for sorting and searching user defined records such as Item records (Item code, name, cost, quantity etc) using vector container. 31 | 32 | Experiment No. 7 : Write a program in C++ to use map associative container. The keys will be the names of states and the values will be the populations of the states. When the program runs, the user is prompted to type the name of a state. The program then looks in the map, using the state name as an index and returns the population of the state. 33 | 34 | 35 | 36 | 37 | 38 | 39 | --------------------------------------------------------------------------------