Oops Labmanual - 2
Oops Labmanual - 2
PROGRAMMING LAB
DEPARTMENT OF COMPUTER SCIENCE &
ENGINEERING
CIC-257
Faculty name:
Mrs. Priyanka Kushwaha Student name: Hritik
Group: B
Enrollment no: 00627207222
3. List of experiments 4
5. Projects to be allotted 7
8. Details of the each section of the lab along with the examples,
Programming
PRACTICAL RECORD
Branch : CSE
Section/ Group : B
INDEX
7
[Type here]
Write
i a program to Implement a class string.
Write
n a program to demonstrate the concept of Virtual
Function and Dynamic Binding.
Create
t a class LIST with two pure Virtual Functions
store()
w and retrieve()
Program to raise an exception if an attempt is made torefer
to an element whose index is beyond array size.
t
Program to define a function template for calculatingthe
s re of given numbers with different data type
. 5 | P a g
e
[Type here]
EXPERIMENT -
1
AIM: -
Write a program for multiplication of two matrices using OOPS.
SOFTWARE USED: -
Code blocks (C++).
THEORY: -
Matrix multiplication in C++
We can add, subtract, multiply and divide 2 matrices. To do so, we are taking inputfrom
the user for row number, column number, first matrix elements and second matrix
elements. Then we are performing multiplication on the matrices entered bythe user.
In matrix multiplication first matrix one row element is multiplied by second matrix allcolumn
elements.
CODE: -
#include <iostream>
using namespace std;int
main()
{
int a[10][10],b[10][10],mul[10][10],r,c,i,j,k;
cout<<"enter the number of row=";
cin>>r;
cout<<"enter the number of column=";
cin>>c;
cout<<"enter the first matrix element=\n";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cin>>a[i][j];
}
}
cout<<"enter the second matrix element=\n";
[Type here]
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cin>>b[i][j];
}
}
cout<<"multiply of the matrix=\n";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
mul[i][j]=0;
for(k=0;k<c;k++)
{
mul[i][j]+=a[i][k]*b[k][j];
}
}
}
//for printing result
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cout<<mul[i][j]<<" ";
}
cout<<"\n";
}
return 0;
}
[Type here]
OUTPUT: -
[Type here]
EXPERIMENT 2
AIM: -
Write a program to read and display the details of the student using classes, objects and two
member functions get_details and put_details.
SOFTWARE USED: -
Code blocks (C++).
THEORY: -
Classes in C++
Class is an encapsulation of data and coding. Classes are an expanded version of structures.
Structure can only contain multiple variables. Classes can contain multiple variables, even
more, classes can also contain functions as class member.Variables declared in class are called
Data Members(Attributes). Functions declared or defined in class are called Member
Functions.
CODE: -
#include <iostream>
using namespace std;
class student
{
private:
char name[30];int
rollNo;
public:
void getDetails(void);
void putDetails(void);
};
void student::getDetails(void)
{
cout << "Enter name: " ;
cin >> name;
cout << "Enter roll number: ";
cin >> rollNo;
[Type here]
}
void student::putDetails(void)
{
cout << "Student details:\n";
cout << "Name:"<< name << ",Roll Number:" << rollNo;
}
int main()
{
student s;
s.getDetails();
s.putDetails();
return 0;
}
OUTPUT: -
[Type here]
EXPERIMENT – 3 PROGRAM 1
AIM PROGRAM 1:
Write a program to perform addition of two complex numbers using constructor overloading.
The first constructor which takes no argument is used to create objectswhich are not
initialized, second which takes one argument is used to initialize real and imaginary parts to
equal values and third which takes two arguments is used toinitialize real and imaginary
parts to two different values.
THEORY:
In C++, we can have more than one constructor in a class with same name, as longas each
has a different list of arguments. This concept is known as Constructor Overloading and is
quite similar to function overloading.
• Overloaded constructors essentially have the same name (name of theclass)
and different number of arguments.
• A constructor is called depending upon the number and type of arguments passed.
• While creating the object, arguments must be passed to let compiler know,which
constructor needs to be called.
SOFTWARE USED:
CODE BLOCKS(C++)
CODE:
#include <iostream>
using namespace std;
class Complex
{
{
real = 0;
imaginary = 0;
}
Complex (int num)
[Type here]
{
real = num;
imaginary = num;
cout << "Complex Number : " << real << " + " << imaginary << "i" << endl;
}
Complex (int r, int i)
{
real = r;
imaginary = i;
cout << "Complex Number : " << r << " + " << i << "i" << endl;
}
Complex (Complex &other)
{
real = other.real;
imaginary = other.imaginary;
cout << "Complex Number : " << real << " + " << imaginary << "i" << endl;
}
Complex sum (Complex &a, Complex &b)
{
Complex result; result.real = a.real + b.real;
result.imaginary = a.imaginary + b.imaginary;
cout << "Result : " << result.real << " + " << result.imaginary << "i";
return result;
}};
int main()
{
int r1, r2, i1, i2;
cout << "Enter 1st Number's Real and Imaginary part\n";cin
>> r1 >> i1;
[Type here]
OUTPUT 1:
[Type here]
EXPERIMENT – 3 PROGRAM 2
AIM PROGRAM 2:
SOFTWARE USED:
CODE BLOCKS(C++)
THEORY:
In C++, inheritance is a process in which one object acquires all the properties and
behaviours of its parent object automatically. In such way, you can reuse, extend or modify
the attributes and behaviours which are defined in other class.
In C++, the class which inherits the members of another class is called derived class and the
class whose members are inherited is called base class. The derived class is the specialized
class for the base class.
CODE:
#include <iostream>
using namespace std;
class multiply
{
public:
int x;
void getdata_x()
{
cout << "Enter the value of x = ";
cin >> x;
}
};
class derive : public multiply
{
private:
[Type here]
int y;
public:
void getdata_y()
{ cout << "Enter the value of y = ";
cin >> y;
} void product()
{ cout << "Product = " << x * y;
} };
int main()
{
derive a;
a.getdata_x();
a.getdata_y();
a.product();
return 0;
}
OUTPUT 2:
[Type here]
EXPERIMENT – 3 PROGRAM 3
AIM PROGRAM 3:
SOFTWARE USED:
CODE BLOCKS(C++)
THEORY:
In C++ programming, not only you can derive a class from the base class but you can also
derive a class from the derived class. This form of inheritance is known as multilevel
inheritance.
CODE:
#include <iostream>
using namespace std;
class multiply
{
public:
int x;
void getdata_x()
{
void getdata_y()
{ cout << "\nEnter value of y= "; cin >> y;
}};
[Type here]
}};
int main()
{ ans_2 a;
a.getdata_x();
a.getdata_y();
a.getdata_z();
a.product();
return 0;
}
OUTPUT 3:
[Type here]
EXPERIMENT – 4 PROGRAM 1
AIM PROGRAM 1:
THEORY:
A derived class with two base classes and these two base classes have one common baseclass is
called multipath inheritance.
Ambiguity in C++ occur when a derived class have two base classes and these twobase
classes have one common base class. Consider the following figure:
SOFTWARE USED:
CODE BLOCKS(C++)
CODE:
#include<iostream>
using namespace std;
class Parent1
{ protected:
int num;
public:
Parent1()
{ num = 123456;
}};
class Parent2
{protected:
[Type here]
int num;
public:
Parent2()
{ num = 654321;
} };
class Child: public Parent1, public Parent2
{ public:
void function()
int main()
{ Child obj;
obj.function();
return 0;
}
OUTPUT
[Type here]
EXPERIMENT – 4 PROGRAM 2
AIM PROGRAM 2:
Write a program to find the greatest of two given numbers in two different classesusing
friend function.
SOFTWARE USED:
CODE BLOCKS(C++)
THEORY:
If a function is defined as a friend function in C++, then the protected and privatedata of
a class can be accessed using the function.
By using the keyword friend compiler knows the given function is a friend function.
For accessing the data, the declaration of a friend function should be done inside thebody of a
class starting with the keyword friend.
CODE:
#include<iostream>
using namespace std;
class numb
{private:
int x, y;
public:
void input()
{cout << "Enter two numbers:";
cin >> x>>y;
OUTPUT
[Type here]
EXPERIMENT – 5 PROGRAM 1
AIM
:
Write a program to demonstrate the concept of unary minus operator
overloading with or without using friend function
THEORY:
The operator keyword declares a function specifying what operator-symbol means when
applied to instances of a class. This gives the operator more than one meaning,or "overloads" it.
The compiler distinguishes between the different meanings of an operator by examining the
types of its operands.
The unary operators operate on a single operand and following are the examples of Unary
operators −
CODE:
#include<iostream>
using namespace std;
class space{
int x;
int y;
int z;
public:
void getdata(int a,int b,int c); void display(void);
friend void operator-(space &s);
};
OUTPUT:
[Type here]
EXPERIMENT – 5 PROGRAM 2
AIM:
Implement a class string containing the following functions.
SOFTWARE USED: CODEBLOCKS
THEORY:
String class is created to implement these functions for the string operations.
The program uses the standard C++ library for these functions.The purpose of this programis just to
demonstrate operator overloading to perform these string operations.
Following is the list of the operators overloaded and their effects on the string objects:
1) == : String copy
2) = : String compare
3) + : String concatenation
4) << : Displaying the string from my_string object
5) >> : Reversing the string
6) / : Finding substring
CODE
#include<iostream.h>
#include<stdio.h>
#include<string.h>
#define MAX 50 class
string
{
char str[MAX]; public:
string()
{ strcpy(str,” “);
}
string(char s[])
{
strcpy(str,s);
}
};
{
strcat(str,s1.str); cout<<”\n\nConcatinated
string is: “<<str;
}
else
{
cout<<”\n\nSorry the array size is exceeded.”;
}
}
int main()
{
string s1,s2; int
choice;
char ans;
do
{
cout<<”\n1.Concatination of string\n2.Equal\n3.Copy
string\n; cout<<”\n\nEnter your choice: “; cin>>choice;
switch(choice)
{
case 1:
cout<<”\n\nEnter the first string: “; cin>>s1;
cout<<”\n\nEnter the second string: “;
cin>>s2; s1+s2;
break;
case 2:
cout<<”\n\nEnter the first string: “; cin>>s1;
[Type here]
case 3:
cout<<”\n\nEnter the string: “;
cin>>s1; s2=s1;
break;
default:
cout<<”\n\nPlease enter correct choice.”;
break;
}
cout<<”\n\n\nDo you want to continue?(y/n): “; cin>>ans;
}while(ans==’y’ || ans==’Y');
OUTPUT:
[Type here]
EXPERIMENT – 6 PROGRAM 1
AIM
:
THEORY:
A virtual function is a member function that you expect to be redefined in derived classes.
When you refer to a derived class object using a pointer or a reference to the base class, you
can call a virtual function for that object and execute the derivedclass's version of the
function.
Dynamic binding or late binding is the mechanism a computer program waits until
runtime to bind the name of a method called to an actual subroutine. It is an alternative to
early binding or static binding where this process is performed at compile-time
CODE PART 1:
#include <iostream>
using namespace std;
class Base
{
public:
virtual void print()
{
cout << "Base Function" << endl;
}
};
class Derived : public Base
{
public:
void print()
{
cout << "Derived Function" << endl;
[Type here]
}
};
int main()
{
Derived derived1;
Base* base1 = &derived1;
base1->print();
return 0;
}
OUTPUT: -
[Type here]
CODE PART 2:
#include<iostream>
using namespace std;int
Square(int x)
{
return x * x;
}
int Cube(int x)
{
return x * x * x;
}
main()
{
int x = 2;
int choice;
do
{
cout << "Enter 0 for Square value, 1 for Cube value :\n";cin
>> choice;
}
while (choice < 0 || choice > 1);
int( * ptr)(int);
switch (choice) {
case 0:
ptr = Square;
break;
case 1:
ptr = Cube;
break;
[Type here]
}
cout << "The result is :" << ptr(x);
return 0;
}
OUTPUT: -
[Type here]
EXPERIMENT – 6 PROGRAM 2
AIM:
Create a class LIST with two pure Virtual Functions store() and retrieve().To store avalue
call store() function and to retrieve a value call retrieve() function. Derive two classes stack
and queue from it and override store() and retrieve() function.
THEORY:
A virtual function is declared by using the 'virtual' prefix to the declaration of
that function. A call to virtual function is resolved at the run-time by analyzing the actual
type of object that is calling the function. This is known as dynamic binding.
CODE:
#include<iostream>
#include<stdlib.h>
#include<conio.h>
using namespace std;
struct node
{
int data;
node *next;
};
node *head=NULL,*tail=NULL;
class List
{
public:
void view()
{
node *n = head;
if(head==NULL)
{
[Type here]
cout<<" ";
while(n!=NULL)
{
if(n->next==NULL)
{
cout<<n->data;
}
else
{
cout<<n->data<<"->";
}
n = n->next;
}
}
}
virtual void store(int n)=0;
virtual int retrive()=0;
};
class Stack :public List
{
public:
void store(int n)
{
node *n1 = new node();
n1->data = n;
[Type here]
n1->next=NULL;
if((head==NULL)&&(tail==NULL))
{
head = n1;
tail = n1;
}
else
{
tail->next = n1;
tail = n1;
}
}
int retrive()
{
if((tail==NULL)&&(head==NULL))
{
return -1;
}
else
{
int n = tail->data;
node *n1 = head;
while((n1->next!=tail)&&(head!=tail))
{
n1 = n1->next;
}
n1->next = NULL;
free(tail);
if(head!=tail)
[Type here]
{
tail = n1;
}
else
{
tail=NULL;
head=NULL;
}
return n;
}
}
};
class Queue:public List
{
public:
void store(int n)
{
node *n1 = new node();
n1->data = n;
n1->next=NULL;
if((head==NULL)&&(tail==NULL))
{
head = n1;
tail = n1;
}
else
{
tail->next = n1;
tail = n1;
[Type here]
}
}
int retrive()
{
if((tail==NULL)&&(head==NULL))
{
return -1;
}
else
{
int n = head->data;
if(head==tail)
{
}
else
{
head = head->next;
}
return n;
}
}
};
int main()
{
Stack s1;
int ch;
while(1)
{
[Type here]
system("cls");
cout<<"\n\n Menu";
cout<<"\n\n 1. Stack";
cout<<"\n 2. Queue";
cout<<"\n 3. Exit";
cout<<"\n\n Enter your choice - ";
cin>>ch;
if(ch==1)
{
Stack s1;
int ch1;
while(1)
{
system("cls"); cout<<"\n\n
Stack Menu";
cout<<"\n 1. Push Element";
cout<<"\n 2. Pop Element";
cout<<"\n 3. View Stack";
cout<<"\n 4. Exit";
cout<<"\n\n Enter your choice - ";
cin>>ch1;
if(ch1==1)
{
int element;
cout<<"\n Enter the element you want to push - ";
cin>>element;
s1.store(element); cout<<"\n
Element Pushed";
}
[Type here]
else if(ch1==2)
{
int element=0; element
= s1.retrive();
if(element==-1)
{
cout<<"\n Stack is Empty";
}
else
{
cout<<"\n Element Popped = "<<element;
}
}
else if(ch1==3)
{
cout<<"\n Elements in stack from bottom to top:- ";
s1.view();
}
else if(ch1==4)
{
break;
}
else
{
}
}
[Type here]
else if(ch==2)
{
Queue q1;
int ch1;
while(1)
{
system("cls");
cout<<"\n\n Queue Menu";
}
else if(ch1==2)
{
int element=0; element
= q1.retrive();
if(element==-1)
{
cout<<"\n Queue is Empty";
[Type here]
}
else
{
cout<<"\n Element Popped = "<<element;
}
}
else if(ch1==3)
{
cout<<"\n Elements in queue from front to rear:- ";
q1.view();
}
else if(ch1==4)
{
break;
}
else
{
}
else if(ch==3)
{
exit(0);
}
else
{
cout<<"\n\n Wrong Choice";
[Type here]
}
getch();
}
return 0;
}
OUTPUT:-
[Type here]
[Type here]
[Type here]
[Type here]
EXPERIMENT – 7 PROGRAM 1
AIM:
WAP to raise an exception if an attempt is made to refer to an element whose index isbeyond the
array size.
THEORY-
In C++, exception is an event or object which is thrown at runtime. All exceptions are derived
from std:: exception class. It is a runtime error which can be handled. If we don'thandle the
exception, it prints exception message and terminates the program.
CODE-
#include<iostream>
main()
int arr[]={-1,2};
for(int i=0;i<3;i++)
try
if(i>1)
throw i;
else
cout<<"arr["<<i<<"]="<<arr[i]<<endl;
}
[Type here]
catch(int n)
return 0;
OUTPUT-
[Type here]
EXPERIMENT – 7 PROGRAM 2
AIM:
WAP to define a function template for calculating the square of given numbers withdifferent
data type
THEORY-
Templates are powerful features of C++ which allows you to write generic programs. In simple
terms, you can create a single function or a class to work with different data types using
templates.
A function template works in a similar to a normal function with one key difference. A single
function template can work with different data types at once but, a single normalfunction can
only work with one set of data types.
CODE-
#include <iostream>
inline T square(T x)
{ T result; result
= x * x;return
result;
};
int main()
{ int i, ii;
float x, xx;
double y, yy;
cin>>i;
cin>>x;
cin>>y;
ii = square<int>(i);
xx = square<float>(x);
yy = square<double>(y);
OUTPUT-
[Type here]
EXPERIMENT – 8 PROGRAM 1
AIM: WAP to demonstrate the use of special functions, constructor and destructor in theclass
template. The program is used to find the bigger of two entered numbers.
THEORY:
Templates are powerful features of C++ which allows you to write generic programs. In simple
terms, you can create a single function or a class to work with different data types using
templates.
Templates are often used in larger codebase for the purpose of code reusability andflexibility of
the programs.
Functional Template
A function template works similarly to a normal function, with one key difference.
A single function template can work with different data types at once but a single normalfunction
can only work with one set of data types.
Normally, if you need to perform identical operations on two or more types of data, youuse
function overloading to create two functions with the required function declaration.
CODE:
#include<iostream>
#include<conio.h>
#include<stdio.h>
}
}
~large(){}
};
int main(){
// clrscr();
large<int>g(23,40);
g.largest();
large<float>h(45.4,89.88);
h.largest();
getch();
return 0;
}
OUTPUT :
[Type here]
EXPERIMENT – 8 PROGRAM 2
AIM: Program to read the class object of student info such as name, age, sex, height and weight
from the keyboard and to store them on a specified file using read() and write() functions. Again
the same file is opened for reading and displaying the contentsof the file on the screen.
THEORY:
File handling:
C++ has two basic classes to handle files, ifstream and ofstream. To use them, includethe header
file
fstream. Ifstream handles file input (reading from files), and ofstream handles file output(writing
to
files)
CODE:
//Writing a class object to a file using ofstream class and mode ios::out
#include<iostream>
#include<fstream>
class A
{
private:
char name[40];
int age;
float height;
char gender;
char newline_chr;
public:
void putdata();
void getdata();
[Type here]
};
//Defining the function putdata() to allow user to enter the data member of a object.void A ::
putdata()
{
cout<<"Enter the name : ";
cin.getline(name,40);
cout<<"Enter the age : ";
cin>>age;
cout<<"Enter the height : ";
cin>>height;
cout<<"Enter the gender : ";
cin>>gender;
//This one captures the enter key(newline character) pressed after entering thegender.
cin.get(newline_chr);
void A :: getdata()
{
cout<<"The name is : " << name << "\n";
cout<<"The age is : " << age << "\n";
cout<<"The height is : " << height << "\n";
cout<<"The gender is : " << gender << "\n";
}
int main()
{
//Calling the open function to read and write an object to/from a filefstream_ob.open("File1.txt",
ios::out);
[Type here]
//Calling the write() function to write an array of objects to a file in a binary form.fstream_ob.write( (char
*) & ob1, sizeof(ob1));
//Calling the open function to read and write an object to/from a file
ifstream_ob.open("File1.txt", ios::in);
//Calling the read() function to read an array of objects from a file and transfer itscontent to an
empty object
ifstream_ob.read( (char *) & ob2, sizeof(ob2));
for(int i=0;i<size;i++)
{
//Calling getdata() to read the values of an object just readob2[i].getdata();
}
return 0;
}
OUTPUT :
[Type here]
OOPS CBS-1
Aim: - Write a program having STUDENT as an abstractclass and create derivedclasses
Engineering, Science from it. Create their objects and process them.
Software used: Dev cpp
THEORY:
Abstract Class:
An abstract class is, conceptually, a class that cannot be instantiated and is usuallyimplemented
as a class that has one or more pure virtual (abstract) functions.
A pure virtual function is one which must be overridden by any concrete (i.e., non-abstract)
derived class. This is indicated in the declaration with the syntax " = 0" in the member function's
declaration.
Derived Class:
A class that is created from an existing class. The derived class inherits all members andmember
functions of a base class. The derived class can have more functionality with respect to the Base
class and can easily access the Base class. A Derived class is also called a child class or subclass.
CODE: -
#include<iostream>
#include<conio.h>
using namespace std;
class student
{public:
};
class engineering:public student
{
int r;
{
cout<<"ENGINEERING FACULTY"<<endl;
void display()
{
cout<<endl<<"Name= "<<n;
cout<<endl<<"Roll= "<<r<<endl<<endl;
}
};
class science:public student
{
int r;
char n[10]; public:
void getdata()
{
cout<<"OOPS FACULTY"; cout<<endl<<"Enter name: ";
cin>>n; cout<<"Enter roll: "; cin>>r;
void display()
{
cout<<endl<<"Name="<<n; cout<<endl<<"Roll="<<r<<endl<<endl;
}
};
int main()
{
[Type here]
ptr[0]->display(); ptr[2]=&s;
ptr[2]->getdata();
ptr[2]->display();
getch();
OUTPUT: -
[Type here]
[Type here]
CBS – 2 OOPS
AIM – Develop Hospital Management System using all concept of object-oriented
programming.
THEORY:
Object-oriented programming – As the name suggests uses objects in programming. Object-
oriented programming aims to implement real-world entities like inheritance, hiding,
polymorphism, etc in programming. The main aim of OOP is to bind together the data and
the functions that operate on them so that no other part of the code canaccess this data except
that function.
Characteristics of an Object-Oriented Programming language
Class: The building block of C++ that leads to Object-Oriented programming is a Class. It is
a user-defined data type, which holds its own data members and memberfunctions, which can
be accessed and used by creating an instance of that class. A class is like a blueprint for an
object.
[Type here]
SOURCE CODE
#include<iostream>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
struct doctor1
{
int id;
char name[20],Q[20],age[20],exp[20],city[20],special[20];
};
struct patient1
{
int id1;
char name[20],age[20],city[20],dis[20],room[20],sym[20],con[20],date[20],charg[20],bill[20];
};
using namespace
std;class doctor;
class
patient;
class
hospital
{
public:
// int
id=0,id1=0,int
counter=0;
};
int i,en;
cout<<"How Many Entries you want to
add :";cin>>en;
for(i=1;i<=en;i++)
{
cout<<"Enter Doctor's ID
:"
;cin>>arr[docid].id;
cout<<"Enter Doctor's Name
:";
cin>>arr[docid].name; cout<<"Enter
Doctor's Age :";
cin>>arr[docid].age;
cout<<"Enter Doctor's Qualification:";
cin>>arr[docid].Q;
cout<<"Enter Doctor's Specialization :";
cin>>arr[docid].special;
cout<<"Enter Doctor's Experience :";
cin>>arr[docid].exp;
cout<<"Enter Doctor's city
:"
;cin>>arr[docid].city;
docid++;
counter++;
cout<<"\n";
cout<<"You filled all Entries of "<<i<<" doctor
successfully"<<"\n";cout<<"enter value for "<<" "<<i+1<<"
"<<"doctor"<<"\n";
}
}
void Display()
{
system("cls"
);int n,i;
cout<<"\n Enter the doctor's ID to display
Record :";cin>>n;
if(n==0)
{
cout<<"\n\n OOPS!!!! "<<"\n\n";
cout<<"Note:- No Record To Display Plz Go Back And Enter Some Entries.
............................................................................................................... "<<"\n";
}
else
{
int status=0;
for(i=0;i<docid;i++)
{
[Type here]
if(arr[i].id==n)
{
status=1
;break;
}
}
if(status)
{
cout<<"\n\n";
cout<<"1.Doctor's ID :"<<arr[i].id<<"\n";
cout<<"2.Doctor's Name :"<<arr[i].name<<"\n";
cout<<"3.Doctor's Age :"<<arr[i].age<<"\n";
cout<<"4.Doctor's Qualification :"<<arr[i].Q<<"\n";
cout<<"5.Doctor's Specialization ...........................
:"<<arr[i].special<<"\n";
cout<<"6.Doctor's Experience
:"<<arr[i].exp<<"\n";
cout<<"8.Doctor's city :"<<arr[i].city<<"\n";
cout<<" \n Press Any KEY To choose another Option
";
}
else
{
cout<<" \n\n No such ID in database "<<endl;
cout<<" \n Press Any KEY To choose another Option ";
}
}
getch();
}
void doctor_detail()
{
int i;
if(docid==0
)
{
cout<<" \n\n\n OOPS!!!! "<<"\n\n";
cout<<"Note:- No Record To Display Plz Go Back And Enter Some Entries.
............................................................................................................... "<<"\n";
}
else{
cout<<"****************************"<<"\n"; cout<<"\t \t
\t Details Of All The Doctors In The Hospital \n";
cout<<"****************************"<<"\n
\n";
cout<<"\n \n";
for(i=0;i<docid;i++)
{
cout<<arr[i].id<<"\t \t"<<arr[i].special<<"\t \t \t"<<arr[i].Q<<"\t \t \t"<<arr[i].age<<"\n";
}
cout<<" \n Press Any Button To choose another Option ";
}
getch();
}
void tot_no_of_doc()
{
system("cls"
);int
i=counter;
cout<<"Total Doctor's in Hospital : "<<i<<"\n";
cout<<" \n Press Any Button To choose another Option
"
;getch();
}
};
}
else
{
int status=0;
for(i=0;i<docid1;i++)
[Type here]
{
if(arr[i].id1==n)
{
status=1
;break;
}
}
if(status==1)
{
cout<<"1.Patient's ID :"<<arr[i].id1<<"\n";
cout<<"2.Patient's Name
:"<<arr[i].name<<"\n";
cout<<"3.Patient's Age :"<<arr[i].age<<"\n";
cout<<"4.Patient's Disease :"<<arr[i].dis<<"\n";
cout<<"5.Patient's Symptoms
:"<<arr[i].sym<<"\n";
cout<<"6.Patient's Room No. :"<<arr[i].room<<"\n";
cout<<"7.Patient's condition Before Admit
:"<<arr[i].con<<"\n";
cout<<"8.Patient's ADMIT Date :"<<arr[i].date<<"\n";
cout<<"9.Patient's Room Charge
:"<<arr[i].charg<<"\n
";cout<<"10.Patient's Medicine charge
:"<<arr[i].bill<<"\n"
;cout<<" \n Press Any KEY To choose another Option ";
}
else{
cout<<" \n\n No such ID in database "<<endl;
cout<<" \n Press Any KEY To choose another Option ";
}
}
getch();
}
}
}
if(status)
{
cout<<"\n\n * Patient's Report * "<<"\n \n";
cout<< "1. Patient's Name "<<arr[i].name<<"\n";
cout<< "2. Patient's Age "<<arr[i].age<<"\n";
cout<< "3. Patient symptoms
"<<arr[i].sym<<"\n";
cout<< "4. Patient Disease "<<arr[i].dis<<"\n";
cout<< "5. Patient Admit Date "<<arr[i].date<<"\n";
cout<< "6. Patient condition At The Time Of Discharge
"<<arr[i].con<<"\n";cout<<"Press Any Key To Go Back. ";
}
else{
cout<<" \n\n No such ID in database "<<endl;
cout<<" \n Press Any KEY To choose another Option ";
}
getch();
}
else{
cout<<" \n\n No such ID in database "<<endl;
cout<<" \n Press Any KEY To choose another Option ";
}
getch();
}
[Type here]
int main()
{
//system("color B0");
if(ch1==1)
{
xyz2:
system("cls")
;
cout<<"\n\n";
cout<<" 1. Enter into Doctor's DataBase
"<<endl;cout<<" 2. Enter into Patient's DataBase
"<<endl;cout<<" 3. Generate Patient's Report
"<<endl;
cout<<" 4. Generate Patient's Bill "<<endl;
cout<<" 5. EXIT "<<"\n\n";
cout<<" Please Enter Your choice :"<<" ";
cin>>ch2;
while(repeat==true)
{
system("cls"
);
switch(ch2)
case 1:
{
cout<<"\n";
cout<<" * Welcome To Doctor's DataBase * "<<"\n\n";
case 3:
system("cls");
d.doctor_detail(
);break;
case 4:
d.tot_no_of_doc();
break;
case 5:
goto
xyz2;
break;
default:
cout<<"invalid"
;
}
break
;case 2:
cout<<"\n\n";
cout<<" * Welcome To Patient's DataBase * "<<"\n\n";
case 3:
system("cls");
p.patient_detail()
;break;
case 4:
p.tot_no_of_pat();
break;
case 5:
goto
xyz2;
break;
default:
cout<<"invalid"
;break;
}
break;
case 3:
p.patient_report();
goto xyz2;
break;
case 4:
p.gen_pat_report(
);goto xyz2;
break;
[Type here]
case 5:
goto
xyz;
break;
}
}
}
else if(ch1==2)
{
return 0;
}
else
{
cout<<"Wrong Input"<<endl;
}
return 0;
}
[Type here]
OUTPUT
[Type here]
[Type here]