OOMP Practicals
---------------------------------------------------
OOMP Oral :
---------------------------------------------------
Group A:
---------------------------------------------------
OOMP Program :
---------------------------------------------------
//============================================================================
// Author: Aman Bohra
// ( bohraaman.blogspot.in)
// ROLL NO : 007
// CLASS : SE(COMPUTER)
// BATCH : S1
// ASSIGNMENT NO.: 1
/* TITLE :Create a class named weather report that holds a daily weather report with data
members day_of_month,hightemp,lowtemp,amount_rain and amount_snow. The
constructor initializes the fields with default values: 99 for day_of_month, 999 for
hightemp,-999 for low emp and 0 for amount_rain and amount_snow. Include a
function that prompts the user and sets values for each field so that you can override
the default values. Write a C++/Java/Python program that creates a monthly report.
d) Menu driven program with options to Enter data and Display report
e) Report Format
//============================================================================*/
#include<stdio.h>
#include<iostream>
using namespace std;
class weather
{
int day,month;
float low_temp,high_temp;
float rain_amt,snow_amt;
public:
weather();
void getdata(int);
void putdata();
float l()
{
return low_temp;
}
float h()
{
return high_temp;
}
float r()
{
return rain_amt;
}
float s()
{
return snow_amt;
}
};
weather :: weather()
{
day = 99;
low_temp = -999;
high_temp = -999;
rain_amt = 0;
snow_amt = 0;
}
void getdata(int *m1,int *d1)
{
cout<<"\n ENTER THE MONTH NUMBER: ";
cin>>*m1;
cout<<"\n ENTER THE DAY NUMBER: ";
cin>>*d1;
return ;
}
void weather :: getdata(int d)
{
day=d;
cout<<"\n HIGH TEMPERATURE: ";
cin>>high_temp;
cout<<"\n LOW TEMPERATURE: ";
cin>>low_temp;
cout<<"\n AMOUNT OF RAIN IN CENTIMETER: ";
cin>>rain_amt;
cout<<"\n AMOUNT OF SNOW: ";
cin >> snow_amt;
return ;
}
void weather :: putdata()
{
cout<<"\t"<<day;
cout<<"\t "<<high_temp;
cout<<"\t\t"<<low_temp;
cout<<"\t\t "<<rain_amt;
cout<<"\t\t "<<snow_amt;
return ;
}
main()
{
weather weather[12][31];
int ch,day,month,d=0;
float sum=0,avg=0,a=0,b=0,e=0,f=0,g=0,h=0,l=0,j=0,k=0;
cout<<"\n\n.*..*..*..* WEATHER REPORT *..*..*..*..";
do
{
cout<<"\n\n MENU: ";
cout<<"\n\n\t 1. INSERT ";
cout<<"\n\n\t 2. DISPLAY ";
cout<<"\n\n\t 3. EXIT ";
cout<<"\n\n Enter your choice: ";
cin>>ch ;
switch(ch)
{
case 1 :
getdata(&month,&day);
weather[month][day].getdata(day);
break;
case 2:
cout<<"\n\nENTER THE MONTH: ";
cin>>month ;
cout<<"\n\n———————————————————————";
cout<<"\n\tDAY \t HIGH \t\t LOW \t\t RAIN \t\t SNOW";
cout<<"\n———————————————————————\n";
for(int i=1 ; i<=31 ; i++)
{
cout<< "\n" <<i;
weather[month][i].putdata();
if(weather[month][i].l()!=-999)
{
sum=sum+weather[month][i].l();
d=d+1;
}
if(weather[month][i].h()!=-999)
{
a=a+weather[month][i].h();
b=b+1;
}
if(weather[month][i].r()!=0)
{
e=e+weather[month][i].r();
f=f+1;
}
if(weather[month][i].s()!=0)
{
g=g+weather[month][i].s();
h=h+1;
}
}
avg=sum/d;
l=a/b;
j=e/f;
k=g/h;
cout<<"\n\n\tAVG:\t "<<l<<" \t "<<avg<<" \t\t "<<j<<" \t\t"<<k ;
break;
}
}while(ch!=3);
return 0;
}
/* output.......
aman@aman-PIG31T:~/Desktop$ ./a.out
.*..*..*..* WEATHER REPORT *..*..*..*..
MENU:
1. INSERT
2. DISPLAY
3. EXIT
Enter your choice: 1
ENTER THE MONTH NUMBER: 1
ENTER THE DAY NUMBER: 25
HIGH TEMPERATURE: 34
LOW TEMPERATURE: 23
AMOUNT OF RAIN IN CENTIMETER: 13
AMOUNT OF SNOW: 10
MENU:
1. INSERT
2. DISPLAY
3. EXIT
Enter your choice: 1
ENTER THE MONTH NUMBER: 1
ENTER THE DAY NUMBER: 26
HIGH TEMPERATURE: 32
LOW TEMPERATURE: 26
AMOUNT OF RAIN IN CENTIMETER: 26
AMOUNT OF SNOW: 30
MENU:
1. INSERT
2. DISPLAY
3. EXIT
Enter your choice: 2
ENTER THE MONTH: 1
———————————————————————
DAY HIGH LOW RAIN SNOW
———————————————————————
1 99 -999 -999 0 0
2 99 -999 -999 0 0
3 99 -999 -999 0 0
4 99 -999 -999 0 0
5 99 -999 -999 0 0
6 99 -999 -999 0 0
7 99 -999 -999 0 0
8 99 -999 -999 0 0
9 99 -999 -999 0 0
10 99 -999 -999 0 0
11 99 -999 -999 0 0
12 99 -999 -999 0 0
13 99 -999 -999 0 0
14 99 -999 -999 0 0
15 99 -999 -999 0 0
16 99 -999 -999 0 0
17 99 -999 -999 0 0
18 99 -999 -999 0 0
19 99 -999 -999 0 0
20 99 -999 -999 0 0
21 99 -999 -999 0 0
22 99 -999 -999 0 0
23 99 -999 -999 0 0
24 99 -999 -999 0 0
25 25 34 23 13 10
26 26 32 26 26 30
27 99 -999 -999 0 0
28 99 -999 -999 0 0
29 99 -999 -999 0 0
30 99 -999 -999 0 0
31 99 -999 -999 0 0
AVG: 33 24.5 19.5 20
MENU:
1. INSERT
2. DISPLAY
3. EXIT
Enter your choice: 3
aman@aman-PIG31T:~/Desktop$
*/
---------------------------------------------------
Program 2:
---------------------------------------------------
/*==============================================================================================================
TITLE
: A book shop maintains the inventory of books that are being sold at
the shop. The list
includes details such as author, title, price, publisher and stock
position. Whenever a
customer wants a book, the sales person inputs the title and author
and the system
searches the list and displays whether it is available or not. If it
is not, an appropriate
message is displayed. If it is, then the system displays the book
details and requests
for the number of copies required. If the requested copies book
details and requests
for the number of copies required. If the requested copies are
available, the total cost
of the requested copies is displayed; otherwise
the message “Required copies not in
stock” is displayed.Design a system using a
class called books with suitable member functions and
Constructors. Use new
operator in constructors to allocate memory space required.
Implement C++ program for the
system.
ASSIGNMENT NO. : 02
GROUP
: A
ROLL NO. : 07
BATCH
:
S1
===============================================================================================================*/
#include
<iostream>
#include<string.h>
using namespace
std;
class book
{
public:
char
author[50];
char publisher[50];
char bookname[50];
float price;
int copies;
book()
{
char *bookname=new
char[50];
char *author=new
char[50];
char
*publisher=new char[50];
int
copies=0;
float
price=0.0;
}
void
accept();
void display();
};
void
book::accept()
{
cout<<"\n\n\t\t
Enter TITLE : ";
cin>>bookname;
cout<<"\n\n\t\t Enter AUTHOR NAME : ";
cin>>author;
cout<<"\n\n\t\t
Enter PUBLISHER : ";
cin>>publisher;
cout<<"\n\n\t\t Enter NUMBER OF COPIES AVAILABLE : ";
cin>>copies;
cout<<"\n\n\t\t
Enter PRICE OF A SINGLE BOOK : ";
cin>>price;
}
void book::display()
{
cout<<"\n\t "<<bookname<<" |\t|
"<<author<<" |\t| "<<publisher<<"
|\t| "<<copies<<" |\t| "<<price<<"
\n ";
}
int main()
{
book
b[30];
char nm[50],auth[50];
int i,count=0,ch,cpy;
float total;
cout<<"\n\n\t\t\t ***** PROGRAM FOR BOOKS RECORD
*****";
cout<<"\n\t\t-----------------------------------------------------------------------";
do
{
cout<<"\n\n\t\t **** MENU ****";
cout<<"\n\n\t 1]. Enter Details of
Books";
cout<<"\n\t
2]. Display Available Books";
cout<<"\n\t 3]. Search for a Book";
cout<<"\n\t 4]. Exit";
cout<<"\n\n\t\t Enter your choice
: ";
cin>>ch;
switch(ch)
{
case 1: cout<<"\n\n\t\t
Please enter book deatils as asked below";
b[count].accept();
count++;
break;
case 2: cout<<"\n\n\t\t Available books
are as follows";
cout<<"\n\n\t TITLE | | AUTHOR |
| PUBLISHER | | COPIES | | PRICE \n ";
for(i=0;i<count;i++)
{
b[i].display();
}
break;
case 3: cout<<"\n\n\t\t Search for a
book you want to buy";
cout<<"\n\n\t\t
Enter the name of a book : ";
cin>>nm;
cout<<"\n\n\t\t Enter author name : ";
cin>>auth;
for(i=0;i<count;i++)
{
if(strcmp(nm,b[i].bookname)==0 &&
strcmp(auth,b[i].author)==0)
{
cout<<"\n\n\t\t Entered books is
available to us and its details are as given below";
b[i].display();
cout<<"\n\n\t Enter how many copies you want to buy :
";
cin>>cpy;
if(b[i].copies>=cpy)
{
total=cpy*b[i].price;
cout<<"\n\n\t\t
Entered number of copies are available to us";
cout<<"\n\n\t\t
Total price of book "<<nm<<" with number of
copies "<<cpy<<" is : "<<total;
}
else
{
cout<<"\n\n\t\t Entered number of copies are not available
to us";
}
}
else
{
cout<<"\n\n\t\t Entered name of book is not available to
us";
}
}
break;
case 4: return 1;
break;
}
}while(ch!=4);
return 0;
}
//************ OUTPUT **************//
/*
***** PROGRAM FOR BOOKS RECORD *****
-----------------------------------------------------------------------
**** MENU ****
1]. Enter Details of Books
2].
Display Available Books
3]. Search for a
Book
4]. Exit
Enter your choice : 1
Please enter book deatils as asked
below
Enter TITLE
: Programming_with_CPP
Enter AUTHOR NAME : Balguru_Samay
Enter PUBLISHER : MC_GRAW_HILL
Enter NUMBER OF COPIES AVAILABLE : 15
Enter PRICE OF A SINGLE BOOK : 450
**** MENU ****
1]. Enter Details of Books
2].
Display Available Books
3]. Search for a
Book
4]. Exit
Enter your choice : 1
Please enter book deatils as asked
below
Enter TITLE
: Programming_with_java
Enter AUTHOR NAME : Balguru_Samay
Enter PUBLISHER : MC_GRAW_HILL
Enter NUMBER OF COPIES AVAILABLE : 15
Enter PRICE OF A SINGLE BOOK : 550
**** MENU ****
1]. Enter Details of Books
2].
Display Available Books
3]. Search for a
Book
4]. Exit
Enter your choice : 1
Please enter book deatils as asked
below
Enter TITLE
: Baiscs_Of_C
Enter
AUTHOR NAME : Yashwant_Kanetkar
Enter PUBLISHER : Vision
Enter NUMBER OF COPIES AVAILABLE : 25
Enter PRICE OF A SINGLE BOOK : 600
**** MENU ****
1]. Enter Details of Books
2].
Display Available Books
3]. Search for a
Book
4]. Exit
Enter your choice : 1
Please enter book deatils as asked
below
Enter TITLE
: Let_us_C
Enter
AUTHOR NAME : Yashawant_kanetkar
Enter PUBLISHER : Pearson
Enter NUMBER OF COPIES AVAILABLE : 20
Enter PRICE OF A SINGLE BOOK : 500
**** MENU ****
1]. Enter Details of Books
2].
Display Available Books
3]. Search for a
Book
4]. Exit
Enter your choice : 1
Please enter book deatils as asked
below
Enter TITLE
: Modern_Digital_electronics
Enter AUTHOR NAME : RP_Jain
Enter PUBLISHER : Vision
Enter NUMBER OF COPIES AVAILABLE : 28
Enter PRICE OF A SINGLE BOOK : 650
**** MENU ****
1]. Enter Details of Books
2].
Display Available Books
3]. Search for a
Book
4]. Exit
Enter your choice : 2
Available books are as follows
TITLE
| | AUTHOR
| | PUBLISHER | |COPIES|
|PRICE
Programming_with_CPP
| | Balguru_Samay |
| MC_GRAW_HILL | | 15 | |
450
Programming_with_java
| | Balguru_Samay |
| MC_GRAW_HILL | | 15 | |
550
Baiscs_Of_C
| | Yashwant_Kanetkar | |
Vision | | 25
| | 600
Let_us_C
| | Yashawant_kanetkar| |
Pearson | | 20 |
| 500
Modern_Digital_electronics |
| RP_Jain
| | Vision |
| 28 | | 650
**** MENU ****
1]. Enter
Details of Books
2]. Display Available
Books
3]. Search for a Book
4]. Exit
Enter
your choice : 3
Search for a book you want to buy
Enter the name of a book : Programming_with_CPP
Enter author name : Balguru_Samay
Entered books is available to us and its
details are as given below:
TITLE
| | AUTHOR | |
PUBLISHER | |COPIES| |PRICE
Programming_with_CPP | | Balguru_Samay |
| MC_GRAW_HILL | | 15 | |
450
Enter how many copies you
want to buy : 5
Entered number of copies are available to us
Total price of book Programming_with_CPP
with number of copies 5 is : 2250
**** MENU ****
1]. Enter
Details of Books
2]. Display Available
Books
3]. Search for a Book
4]. Exit
Enter
your choice : 3
Search for a book you want to buy
Enter the name of a book : Programming_with_CPP
Enter author name : Balguru_Samay
Entered books is available to us and its
details are as given below:
TITLE
| | AUTHOR | |
PUBLISHER | |COPIES| |PRICE
Programming_with_CPP | | Balguru_Samay |
| MC_GRAW_HILL | | 15 | |
450
Enter
how many copies you want to buy : 25
Entered number of copies are not available to us
**** MENU ****
1]. Enter Details of Books
2].
Display Available Books
3]. Search for a
Book
4]. Exit
Enter your choice : 3
Search for a book you want to buy
Enter the name of a book : Cpp_Baiscs
Enter author name : Blaguru_Samay
Entered name of book is not available to
us
**** MENU
****
1]. Enter Details of Books
2]. Display Available Books
3].
Search for a Book
4]. Exit
Enter your choice : 4
*/
---------------------------------------------------
Program 3:
---------------------------------------------------
//============================================================================
//
ROLL NO :
// CLASS
: SE(COMPUTER)
// BATCH :
S1
// ASSIGNMENT NO.: 3
/* TITLE : Develop an
object oriented program in C++ to create a
database of the personnel information system
containing the following
information: Name, Date of Birth, Blood group,
Height, Weight, Insurance Policy, number, Contact
address, telephone
number,driving license no. etc Construct the
database with suitable member functions for
initializing and destroying the
data viz constructor, default constructor,
copy, constructor, destructor, static member functions,
friend class, this pointer,
inline code and dynamic
memory allocation operators-new and
delete.
//============================================================================*/
#include<iostream>
#include<string.h>
using
namespace std;
class info
{
public:
int dob;
char add[30];
char name[30],bld_grp[3];
float ht,wt;
long ins_no,drv_no,tel_no;
static int cnt;
info();
info(info &);
void accept();
void display();
static int count();
};
info::info()
{
strcpy(name,"Default");
strcpy(bld_grp,"o+");
strcpy(add,"Default");
ht=0;wt=0;
drv_no=0;ins_no=0;
tel_no=10;dob=110;
}
info::info(info &p)
{
strcpy(name,p.name);
strcpy(bld_grp,p.bld_grp);
ht=p.ht;
wt=p.wt;
drv_no=p.drv_no;
ins_no=p.ins_no;
tel_no=p.tel_no;
dob=p.dob;
}
void info::accept()
{
cout<<"Enter the name::";
cin>>name;
cout<<"Enter the
address:";
cin>>add;
cout<<"Enter the blood group:";
cin>>bld_grp;
cout<<"Enter
telephone number:";
cin>>tel_no;
cout<<"Enter driving license no:";
cin>>drv_no;
cout<<"Enter
insurance policy no:";
cin>>ins_no;
cout<<"Enter height:";
cin>>ht;
cout<<"Enter
weight:";
cin>>wt;
cout<<"Enter date of birth:";
cin>>dob;
}
void info::display()
{
cout<<"\n\nName:"<<this->name;
cout<<"\nAddress:"<<this->add;
cout<<"\nBlood group:"<<this->bld_grp;
cout<<"\nTelephone number:"<<this->tel_no;
cout<<"\nDriving license no:"<<this->drv_no;
cout<<"\nInsurance policy no:"<<this->ins_no;
cout<<"\nHeight:"<<this->ht;
cout<<"\nWeight:"<<this->wt;
cout<<"\nDate of birth:"<<this->dob;
}
int
info::cnt=0;
int info::count()
{
cnt=cnt+1;
return(cnt);
}
int
main()
{
int ch,i,n,ch1,pos,temp,flag=0;
info o[50];
char name[12];
do
{
cout<<"\n\n==============" ;
cout<<"\n MENU";
cout<<"\n==============";
cout<<"\n1.Accept";
cout<<"\n2.Display";
cout<<"\n3.Insert record";
cout<<"\n4.Search record";
cout<<"\n5.Delete record";
cout<<"\n6.Exit";
cout<<"\nEnter your choice:";
cin>>ch;
switch(ch)
{
case 1:cout<<"\n1.Inbuilt
record..?";
cout<<"\n2.New record..?";
cin>>ch1;
switch(ch1)
{
case
1:
info a1(info o1);
cout<<"\nDefault
values initialized....";
n=info::count();
break;
case 2:
o[n].accept();
n=info::count();
break;
}
break;
case 2:for(i=0;i<n;i++)
{
o[i].display();
}
break;
case 3:cout<<"\nEnter
the position to insert record:";
cin>>pos;
n=info::count();
pos=pos-1;
for(i=n;i>=pos;i--)
{
temp=pos;
o[i+1]=o[i];
}
o[temp].accept();
break;
case 4:cout<<"Enter
the name to be searched:";
cin>>name;
for(i=0;i<n;i++)
{
if(strcmp(name,o[i].name)==0)
{
flag=1;
o[i].display();
break;
}
}
if(flag==0)
cout<<"Sorry..
Record not found";
break;
case 5:cout<<"\nEnter the
position to delete record:";
cin>>pos;
pos=pos-1;
for(i=pos;i<n;i++)
{
temp=pos;
o[i]=o[i+1];
}
cout<<"\nRecord is
deleted..";
n=info::cnt-1;
break;
case 6:
break;
}
}while(ch!=6);
return
0;
}
/*
================
OUTPUT
================
==============
MENU
==============
1.Accept
2.Display
3.Insert
record
4.Search record
5.Delete record
6.Exit
Enter your
choice:1
1.Inbuilt record..?
2.New record..?1
Default
values initialized....
==============
MENU
==============
1.Accept
2.Display
3.Insert
record
4.Search record
5.Delete record
6.Exit
Enter your
choice:2
Name:Default
Address:Default
Blood
group:o+
Telephone number:10
Driving license no:0
Insurance
policy no:0
Height:0
Weight:0
Date of
birth:110
==============
MENU
==============
1.Accept
2.Display
3.Insert
record
4.Search record
5.Delete record
6.Exit
Enter your
choice:1
1.Inbuilt record..?
2.New record..?2
Enter the
name::Ravi
Enter the address:Mumbai
Enter the blood
group:A-
Enter telephone number:24167388
Enter driving license
no:1234
Enter insurance policy no:1234
Enter height:5.4
Enter
weight:61.7
Enter date of birth:1994
==============
MENU
==============
1.Accept
2.Display
3.Insert
record
4.Search record
5.Delete record
6.Exit
Enter your
choice:2
Name:Default
Address:Default
Blood
group:o+
Telephone number:10
Driving license no:0
Insurance
policy no:0
Height:0
Weight:0
Date of
birth:110
Name:Ravi
Address:Mumbai
Blood
group:A-
Telephone number:24167388
Driving license
no:1234
Insurance policy no:1234
Height:5.4
Weight:61.7
Date
of birth:1994
==============
MENU
==============
1.Accept
2.Display
3.Insert
record
4.Search record
5.Delete record
6.Exit
Enter your
choice:3
Enter the position to insert record:1
Enter the
name::Aman
Enter the address:Abc
Enter the blood group:A+
Enter
telephone number:24145426
Enter driving license no:2332
Enter
insurance policy no:4321
Enter height:5.6
Enter weight:59
Enter
date of birth:1994
==============
MENU
==============
1.Accept
2.Display
3.Insert
record
4.Search record
5.Delete record
6.Exit
Enter your
choice:3
Enter the position to insert record:2
Enter the
name::Umesh
Enter the address:Nashik
Enter the blood
group:B+
Enter telephone number:23456788
Enter driving license
no:5432
Enter insurance policy no:2345
Enter height:5.5
Enter
weight:60
Enter date of birth:1994
==============
MENU
==============
1.Accept
2.Display
3.Insert
record
4.Search record
5.Delete record
6.Exit
Enter your
choice:2
Name:Navin
Address:Deolali
Blood
group:A+
Telephone number:24145426
Driving license
no:2332
Insurance policy no:4321
Height:5.6
Weight:59
Date
of birth:1994
Name:Umesh
Address:Nashik
Blood
group:B+
Telephone number:23456788
Driving license
no:5432
Insurance policy no:2345
Height:5.5
Weight:60
Date
of birth:1994
Name:Default
Address:Default
Blood
group:o+
Telephone number:10
Driving license no:0
Insurance
policy no:0
Height:0
Weight:0
Date of
birth:110
Name:Ravi
Address:Mumbai
Blood
group:A-
Telephone number:24167388
Driving license
no:1234
Insurance policy no:1234
Height:5.4
Weight:61.7
Date
of birth:1994
==============
MENU
==============
1.Accept
2.Display
3.Insert
record
4.Search record
5.Delete record
6.Exit
Enter your
choice:4
Enter the name to be
searched:Ravi
Name:Ravi
Address:Mumbai
Blood
group:A-
Telephone number:24167388
Driving license
no:1234
Insurance policy no:1234
Height:5.4
Weight:61.7
Date
of birth:1994
==============
MENU
==============
1.Accept
2.Display
3.Insert
record
4.Search record
5.Delete record
6.Exit
Enter your
choice:5
Enter the position to delete record:2
Record
is deleted..
==============
MENU
==============
1.Accept
2.Display
3.Insert
record
4.Search record
5.Delete record
6.Exit
Enter your
choice:2
Name:Aman
Address:abc
Blood
group:A+
Telephone number:24145426
Driving license
no:2332
Insurance policy no:4321
Height:5.6
Weight:59
Date
of birth:1994
Name:Default
Address:Default
Blood
group:o+
Telephone number:10
Driving license no:0
Insurance
policy no:0
Height:0
Weight:0
Date of
birth:110
Name:Ravi
Address:Mumbai
Blood
group:A-
Telephone number:24167388
Driving license
no:1234
Insurance policy no:1234
Height:5.4
Weight:61.7
Date
of birth:1994
==============
MENU
==============
1.Accept
2.Display
3.Insert
record
4.Search record
5.Delete record
6.Exit
Enter your
choice:5
Enter the position to delete record:2
Record
is deleted..
==============
MENU
==============
1.Accept
2.Display
3.Insert
record
4.Search record
5.Delete record
6.Exit
Enter your
choice:2
Name:Aman
Address:abc
Blood
group:A+
Telephone number:24145426
Driving license
no:2332
Insurance policy no:4321
Height:5.6
Weight:59
Date
of birth:1994
Name:Ravi
Address:Mumbai
Blood
group:A-
Telephone number:24167388
Driving license
no:1234
Insurance policy no:1234
Height:5.4
Weight:61.7
Date
of birth:1994
Name:Default
Address:Default
Blood
group:o+
Telephone number:10
Driving license no:0
Insurance
policy no:0
Height:0
Weight:0
Date of
birth:110
==============
MENU
==============
1.Accept
2.Display
3.Insert
record
4.Search record
5.Delete record
6.Exit
Enter your
choice:6
*/
---------------------------------------------------
Program 4:
---------------------------------------------------
#include <iostream>
using namespace std;
class
Complex
{
public :
int Real,Imaginary,i,No,n,Choice;
Complex()
{
Real=0;
Imaginary=0;
}
Complex(int R,int I)
{
Real=R;
Imaginary=I;
}
void Input()
{
cout<<"\n\nX : "; cin>>Real;
cout<<"\n\nY : ";
cin>>Imaginary;
}
Complex operator +(Complex C1)
{
Complex C;
C.Real=Real+C1.Real;
C.Imaginary=Imaginary+C1.Imaginary;
return C;
}
Complex operator
-(Complex C2)
{
Complex C;
C.Real=Real-C2.Real;
C.Imaginary=Imaginary-C2.Imaginary;
return C;
}
Complex operator
*(Complex C3)
{
Complex C;
C.Real=Real*C3.Real-Imaginary*C3.Imaginary;
C.Imaginary=Real*C3.Imaginary+Imaginary*C3.Real;
return C;
}
Complex operator /(Complex C4)
{
Complex
C;
float
Div=C4.Real*C4.Real+C4.Imaginary*C4.Imaginary;
float
R=Real*C4.Real+Imaginary*C4.Imaginary;
float
I=-(Real*C4.Imaginary+Imaginary*C4.Real);
C.Real=R/Div;
C.Imaginary=I/Div;
return C;
}
friend void
Output(Complex C);
};
void Output(Complex C)
{
cout<<"\n\nAnswer : "<<C.Real<<" + i
"<<C.Imaginary<<endl;
}
int main()
{
int Choice,ch;
Complex obj,Obj1,Obj2,Obj3;
cout<<"\n\n\n\t
**************************************************************************************************";
cout<<"\n\n\t\t\tProgram to perform arithmetic operations
of two complex numbers using operator overloading";
cout<<"\n\n\n\t
**************************************************************************************************";
do
{
cout<<"\n\n\t\t
Select Your Choice : ";
cout<<"\n\n\t 1]. Using default constructor";
cout<<"\n\n\t 2]. Using user defined constructor";
cout<<"\n\n\t 3]. Exit";
cout<<"\n\n\t\t Enter your choice : ";
cin>>ch;
switch(ch)
{
case 1: Output(obj);
break;
case 2:
do
{
cout<<"\n\n===========";
cout<<"\n
MENU ";
cout<<"\n============";
cout<<"\n\n1.
Addition Of Two Complex Numbers";
cout<<"\n2. Subtraction Of Two Complex
Numbers ";
cout<<"\n3. Multiplication Of Two Complex Numbers";
cout<<"\n4. Division
Of Two Complex Numbers";
cout<<"\n5. Exit";
cout<<"\n\nWhich
Operation Do You Want To Perform ? : ";
cin>>Choice;
if(Choice!=5)
{
cout<<"\n\nEnter 1st
Complex Number";
Obj1.Input();
cout<<"\n\nEnter 2nd
Complex Number";
Obj2.Input();
}
switch(Choice)
{
case 1 : Obj3=Obj1+Obj2;
Output(Obj3);
break;
case 2 :
Obj3=Obj1-Obj2;
Output(Obj3);
break;
case 3 : Obj3=Obj1*Obj2;
Output(Obj3);
break;
case 4 : Obj3=Obj1/Obj2;
Output(Obj3);
break;
case 5 :
return 1;
break;
}
}while(Choice!=5);
break;
case 3: return 1;
break;
}
}while(ch!=3);
return
0;
}
/*
====================================================================
*
Output
*
*
*
*************************************************************************************************
Program to perform arithmetic operations of two complex
numbers using operator overloading
**************************************************************************************************
Select Your Choice :
1]. Using default constructor
2].
Using user defined constructor
3].
Exit
Enter your
choice : 1
Answer : 0 + i 0
Select Your Choice :
1]. Using default constructor
2].
Using user defined constructor
3].
Exit
Enter your
choice : 2
===========
MENU
============
1. Addition Of Two Complex Numbers
2.
Subtraction Of Two Complex Numbers
3. Multiplication Of Two
Complex Numbers
4. Division Of Two Complex Numbers
5.
Exit
Which Operation Do You Want To Perform ? : 1
Enter
1st Complex Number
X : 10
Y : 20
Enter
2nd Complex Number
X : 20
Y : 10
Answer
: 30 + i 30
===========
MENU
============
1. Addition Of Two Complex Numbers
2.
Subtraction Of Two Complex Numbers
3. Multiplication Of Two
Complex Numbers
4. Division Of Two Complex Numbers
5.
Exit
Which Operation Do You Want To Perform ? : 2
Enter
1st Complex Number
X : 20
Y : 20
Enter
2nd Complex Number
X : 10
Y : 10
Answer
: 10 + i 10
===========
MENU
============
1. Addition Of Two Complex Numbers
2.
Subtraction Of Two Complex Numbers
3. Multiplication Of Two
Complex Numbers
4. Division Of Two Complex Numbers
5.
Exit
Which Operation Do You Want To Perform ? : 3
Enter
1st Complex Number
X : 10
Y : 10
Enter
2nd Complex Number
X : 5
Y : 5
Answer :
0 + i 100
===========
MENU
============
1. Addition Of Two Complex Numbers
2.
Subtraction Of Two Complex Numbers
3. Multiplication Of Two
Complex Numbers
4. Division Of Two Complex Numbers
5.
Exit
Which Operation Do You Want To Perform ? : 4
Enter
1st Complex Number
X : 10
Y : 10
Enter
2nd Complex Number
X : 5
Y : 5
Answer :
2 + i -2
===========
MENU
============
1. Addition Of Two Complex Numbers
2.
Subtraction Of Two Complex Numbers
3. Multiplication Of Two
Complex Numbers
4. Division Of Two Complex Numbers
5.
Exit
Which Operation Do You Want To Perform ? : 5
*
*/
---------------------------------------------------
Program 5:
---------------------------------------------------
/*=============================================================================================================
*
Assignment No. : 05
* Title : Write a C++ program to perform
String operations
i. = Equality
ii. == String Copy
iii. + Concatenation
iv. << To display a string
v. >> To reverse a string
vi. Function to determine
whether a string is a palindrome
To find occurrence of a sub-string. Use Operator
Overloading
Roll no :
Batch : S
Group :
A
===============================================================================================================
*/
#include<iostream>
#include<string.h>
using
namespace std;
class strng
{
char
str[20];
int len;
public:
strng()
{
len=0;
}
void accept()
{
cout<<"\n\n\t\t Enter String : ";
cin>>str;
}
friend
ostream & operator <<(ostream & out,strng & s)
{
out<<s.str;
return(out);
}
int operator~()
//Length operator
{
int i;
for(i=0;str[i]!='\0';i++)
{
len++;
}
return(len);
}
void operator+(strng
s2) //Concatenate operator
{
len=0;
~*this;`
int j=len,i;
for(i=0;s2.str[i]!='\0';i++)
{
str[j]=s2.str[i];
j++;
}
str[j]='\0';
cout<<"\n\n\t\t Concatenation is : "<<str;
}
void
operator-()
{
len=0;
~*this;
int j;
cout<<"\n\n\t\t
Reverse of string is : ";
for(j=len-1;j>=0;j--)
{
cout<<str[j];
}
}
void operator!()
//palindrome operator
{
len=0;
~*this;
int i=0,j=len-1,flag;
for(i=0;str[i]!='\0';i++)
{
if(str[i]==str[j])
{
flag=1;
j--;
}
else
{
flag=0;
}
}
if(flag==1)
{
cout<<"\n\n\t\t Entered string is a
palindrome";
}
else
if(flag==0)
{
cout<<"\n\n\t\t Entered string is not a palindrome";
}
}
void operator==(strng
s2) //Equality operator
{
len=0;
~*this;
int i=0,j=len-1,k=0,flag;
for(i=0;str[i]!='\0';i++)
{
if(k<=j)
{
if(str[i]==s2.str[k])
{
flag=1;
}
else
{
flag=0;
break;
}
}
k++;
}
if(flag==1)
{
cout<<"\n\n\t\t Entered strings are equal";
}
else if(flag==0)
{
cout<<"\n\n\t\t Entered strings is not
a equal";
}
}
void
operator<(strng s2) //Copy
operator
{
len=0;
int k;
for(k=0;s2.str[k]!='\0';k++)
{
len++;
}
int j=0,i;
for(i=0;s2.str[i]!='\0';i++)
{
if(j<=len-1)
{
str[j]=s2.str[i];
}
j++;
}
cout<<"\n\n\t\t Copy is : "<<str;
}
};
int main()
{
strng s1,s2;
int ch,l1;
cout<<"\n\n\t\t!!!!!!!! PROGRAM TO PERFORM VARIOUS STRING
OPERATIONS...... !!!!!!!!!";
do
{
cout<<"\n\n\t
******** MENU.... ********";
cout<<"\n\n\t 1]. Length of a String";
cout<<"\n\t 2]. Concatenate Two
Strings";
cout<<"\n\t
3]. Reverse of String";
cout<<"\n\t 4]. Palindrome";
cout<<"\n\t 5]. Copy";
cout<<"\n\t 6]. Equality";
cout<<"\n\t 7]. Occurence of Sub
string";
cout<<"\n\t
8]. Exit";
cout<<"\n\n\t\t Enter your choice:
";
cin>>ch;
switch(ch)
{
case 1:
s1.accept();
l1=~s1;
cout<<"\n\n\t\t Length of entered string is :
"<<l1;
break;
case 2: s1.accept();
s2.accept();
s1+s2;
break;
case 3: s1.accept();
-s1;
break;
case 4: s1.accept();
!s1;
break;
case 5: s1.accept();
s2.accept();
s1<s2;
break;
case 6: s1.accept();
s2.accept();
s1==s2;
break;
case 7: s1.accept();
cout<<s1;
break;
case 8: return 1;
break;
}
}while(ch!=8);
return
0;
}
/*==================================================================
*
OUTPUT
*==================================================================
*
*
*
!!!!!!!! PROGRAM TO PERFORM VARIOUS STRING
OPERATIONS...... !!!!!!!!!
********
MENU.... ********
1]. Length of a
String
2]. Concatenate Two Strings
3]. Reverse of String
4].
Palindrome
5]. Copy
6]. Equality
7]. Occurence of Sub
string
8]. Exit
Enter your choice: 1
Enter String : AmanD
Length of entered string is : 5
******** MENU.... ********
1].
Length of a String
2]. Concatenate Two
Strings
3]. Reverse of String
4]. Palindrome
5]. Copy
6]. Equality
7]. Occurence of Sub
string
8]. Exit
Enter your choice: 2
Enter String : Aman
Enter String : Bohra
Concatenation is :
AmanBohra
******** MENU....
********
1]. Length of a String
2]. Concatenate Two Strings
3].
Reverse of String
4]. Palindrome
5]. Copy
6]. Equality
7]. Occurence of Sub string
8].
Exit
Enter your
choice: 3
Enter String : Aman
Reverse of string is : namA
******** MENU.... ********
1]. Length
of a String
2]. Concatenate Two
Strings
3]. Reverse of String
4]. Palindrome
5]. Copy
6]. Equality
7]. Occurence of Sub
string
8]. Exit
Enter your choice: 4
Enter String : nitin
Entered string is a palindrome
******** MENU.... ********
1].
Length of a String
2]. Concatenate Two
Strings
3]. Reverse of String
4]. Palindrome
5]. Copy
6]. Equality
7]. Occurence of Sub
string
8]. Exit
Enter your choice: 4
Enter String : Aman
Entered string is not a palindrome
******** MENU.... ********
1].
Length of a String
2]. Concatenate Two
Strings
3]. Reverse of String
4]. Palindrome
5]. Copy
6]. Equality
7]. Occurence of Sub
string
8]. Exit
Enter your choice: 5
Enter String : Aman
Enter String : umesh
Copy is : umesh
s1.get();
s2.get();
s1+s2;
break;
******** MENU.... ********
1]. Length of a String
2].
Concatenate Two Strings
3]. Reverse of
String
4]. Palindrome
5]. Copy
6]. Equality
7]. Occurence of Sub string
8].
Exit
Enter your
choice: 6
Enter String : Aman
Enter String : Aman
Entered strings are equal
******** MENU.... ********
1]. Length
of a String
2]. Concatenate Two
Strings
3]. Reverse of String
4]. Palindrome
5]. Copy
6]. Equality
7]. Occurence of Sub
string
8]. Exit
Enter your choice: 6
Enter String : Aman
Enter String : nitin
Entered strings is not a equal
******** MENU.... ********
1].
Length of a String
2]. Concatenate Two
Strings
3]. Reverse of String
4]. Palindrome
5]. Copy
6]. Equality
7]. Occurence of Sub
string
8]. Exit
Enter your choice: 7
Enter String : Aman
******** MENU.... ********
1]. Length
of a String
2]. Concatenate Two
Strings
3]. Reverse of String
4]. Palindrome
5]. Copy
6]. Equality
7]. Occurence of Sub
string
8]. Exit
Enter your choice:
8
*
*
*/
---------------------------------------------------
Program 6:
---------------------------------------------------
/***************************************************************************************************************
TITLE
:
Write a program in C++ using function template to read two matrices
of different data
types such as integers and
floating point values and perform simple arithmetic operations
on these matrices separately and display it.
ASSIGNMENT NO.
: 06
GROUP
: A
ROLL NO.
:
BATCH
:
S
*****************************************************************************************************************/
#include<iostream>
#define
S 3
using namespace std;
template <class T>
class
Matrices
{
public:
T mat[10][10];
int
i,j,k;
Matrices()
{
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
mat[i][j]=0;
}
}
}
void getdata()
{
cout<<"\n\n\t\t Enter Elements in Matrix : ";
for(i=0;i<S;i++)
{
for(j=0;j<S;j++)
{
cout<<"\n\tEnter Element on position : "<<i<<j<<"
:- ";
cin>>mat[i][j];
}
}
}
void disp()
{
cout<<"\n\n\t\t Elements in Matrix Are : \n";
for(i=0;i<S;i++)
{
for(j=0;j<S;j++)
{
cout<<" "<<mat[i][j];
}
cout<<"\n";
}
}
void add(Matrices,Matrices);
void sub(Matrices,Matrices);
void mul(Matrices,Matrices);
};
template
<class T>
void Matrices <T>::add(Matrices N,Matrices
M)
{
cout<<"\n\n\t\t
Addition of Two Matrix is : \n";
for(i=0;i<S;i++)
{
for(j=0;j<S;j++)
{
mat[i][j]=N.mat[i][j]+M.mat[i][j];
}
}
}
template <class T>
void Matrices <T>::sub(Matrices
N,Matrices M)
{
cout<<"\n\n\t\t
Subtraction of Two Matrix is : \n";
for(i=0;i<S;i++)
{
for(j=0;j<S;j++)
{
mat[i][j]=N.mat[i][j]-M.mat[i][j];
}
}
}
template <class T>
void
Matrices <T>::mul(Matrices N,Matrices M)
{
cout<<"\n\n\t\t Multiplication of Two Matrix is : \n";
for(i=0;i<S;i++)
{
for(j=0;j<S;j++)
{
for(k=0;k<S;k++)
{
mat[i][j]=mat[i][j]+(N.mat[i][k]*M.mat[k][j]);
}
}
}
}
int main()
{
Matrices <int> P,Q,A;
Matrices <float>
X,Y,B;
int ch;
int
ch1;
do
{
cout<<"\n\t ==== Matrix DataType Menu
====";
cout<<"\n\t
1]. Enter Int matrix";
cout<<"\n\t 2]. Enter Float matrix";
cout<<"\n\t 3]. Exit";
cout<<"\n\n\t\t Enter Your Choice :
";
cin>>ch;
switch(ch)
{
case 1:
do
{
cout<<"\n\n\t\t
********* MENU **********";
cout<<"\n\n\t 1]. Enter Matrix";
cout<<"\n\t 2]. Display MATRIX";
cout<<"\n\t 3]. ADD TWO MATRIX";
cout<<"\n\t 4]. SUBTRACT TWO MATRIX";
cout<<"\n\t 5]. MULTIPLY TWO MATRIX";
cout<<"\n\n\t\t Enter Your choice : ";
cin>>ch1;
switch(ch1)
{
case 1: cout<<"\n\n\t\t
MATRIX 1 : \n";
P.getdata();
cout<<"\n\n\t\t
MATRIX 2 : \n";
Q.getdata();
break;
case 2:
cout<<"\n\n\t\t
MATRIX 1 : \n";
P.disp();
cout<<"\n\n\t\t
MATRIX 2 : \n";
Q.disp();
break;
case 3:
A.add(P,Q);
A.disp();
break;
case 4:
A.sub(P,Q);
A.disp();
break;
case 5:
A.mul(P,Q);
A.disp();
break;
}
}while(ch1!=5);
break;
case 2: do
{
cout<<"\n\n\t\t ********* MENU
**********";
cout<<"\n\n\t 1].
Enter Matrix";
cout<<"\n\t 2].
Display MATRIX";
cout<<"\n\t 3]. ADD
TWO MATRIX";
cout<<"\n\t 4].
SUBTRACT TWO MATRIX";
cout<<"\n\t
5]. MULTIPLY TWO MATRIX";
cout<<"\n\n\t\t Enter Your choice : ";
cin>>ch1;
switch(ch1)
{
case 1: cout<<"\n\n\t\t
MATRIX 1 : \n";
X.getdata();
cout<<"\n\n\t\t
MATRIX 2 : \n";
Y.getdata();
break;
case 2:
cout<<"\n\n\t\t
MATRIX 1 : \n";
X.disp();
cout<<"\n\n\t\t
MATRIX 2 : \n";
Y.disp();
break;
case 3:
B.add(X,Y);
B.disp();
break;
case 4:
B.sub(X,Y);
B.disp();
break;
case 5:
B.mul(X,Y);
B.disp();
break;
}
}while(ch1!=5);
break;
case 3:
return 1;
break;
}
}while(ch!=3);
return
0;
}
/**********************************************************************************************
*
OUTPUT
**********************************************************************************************
==== Matrix DataType Menu ====
1].
Enter Int matrix
2]. Enter Float
matrix
3]. Exit
Enter Your Choice : 1
********* MENU **********
1]. Enter Matrix
2]. Display
MATRIX
3]. ADD TWO MATRIX
4]. SUBTRACT TWO MATRIX
5].
MULTIPLY TWO MATRIX
Enter Your choice : 1
MATRIX 1 :
Enter Elements in Matrix :
Enter Element
on position : 00 :- 1
Enter Element on position : 01 :- 1
Enter Element on position : 02 :- 1
Enter Element on position : 10 :- 1
Enter Element on position : 11 :- 1
Enter Element on position : 12 :- 1
Enter Element on position : 20 :- 1
Enter Element on position : 21 :- 1
Enter Element on position : 22 :- 1
MATRIX 2 :
Enter Elements in Matrix :
Enter Element
on position : 00 :- 2
Enter Element on position : 01 :- 2
Enter Element on position : 02 :- 2
Enter Element on position : 10 :- 2
Enter Element on position : 11 :- 2
Enter Element on position : 12 :- 2
Enter Element on position : 20 :- 2
Enter Element on position : 21 :- 2
Enter Element on position : 22 :- 2
********* MENU **********
1]. Enter Matrix
2]. Display
MATRIX
3]. ADD TWO MATRIX
4]. SUBTRACT TWO MATRIX
5].
MULTIPLY TWO MATRIX
Enter Your choice : 2
MATRIX 1 :
Elements in Matrix Are :
1 1 1
1 1 1
1 1 1
MATRIX 2 :
Elements in Matrix Are :
2 2 2
2 2 2
2 2 2
********* MENU **********
1]. Enter Matrix
2]. Display
MATRIX
3]. ADD TWO MATRIX
4]. SUBTRACT TWO MATRIX
5].
MULTIPLY TWO MATRIX
Enter Your choice : 3
Addition of Two Matrix is :
Elements in Matrix Are :
3 3 3
3 3 3
3 3 3
********* MENU **********
1]. Enter Matrix
2]. Display
MATRIX
3]. ADD TWO MATRIX
4]. SUBTRACT TWO MATRIX
5].
MULTIPLY TWO MATRIX
Enter Your choice : 4
Subtraction of Two Matrix is :
Elements in Matrix Are :
-1
-1 -1
-1 -1 -1
-1 -1
-1
*********
MENU **********
1]. Enter Matrix
2]. Display MATRIX
3]. ADD TWO
MATRIX
4]. SUBTRACT TWO MATRIX
5]. MULTIPLY TWO MATRIX
Enter Your choice : 5
Multiplication of Two Matrix is :
Elements in Matrix Are :
5
5 5
5 5 5
5 5
5
==== Matrix DataType Menu ====
1]. Enter Int matrix
2]. Enter
Float matrix
3]. Exit
Enter Your Choice : 2
********* MENU **********
1]. Enter Matrix
2]. Display
MATRIX
3]. ADD TWO MATRIX
4]. SUBTRACT TWO MATRIX
5].
MULTIPLY TWO MATRIX
Enter Your choice : 1
MATRIX 1 :
Enter Elements in Matrix :
Enter Element
on position : 00 :- 1.2
Enter Element on position : 01 :- 1.2
Enter Element on position : 02 :- 1.2
Enter Element on position : 10 :- 1.2
Enter Element on position : 11 :- 1.2
Enter Element on position : 12 :- 1.2
Enter Element on position : 20 :- 1.2
Enter Element on position : 21 :- 1.2
Enter Element on position : 22 :- 1.2
MATRIX 2 :
Enter Elements in Matrix :
Enter Element
on position : 00 :- 2.2
Enter Element on position : 01 :- 2.2
Enter Element on position : 02 :- 2.2
Enter Element on position : 10 :- 2.2
Enter Element on position : 11 :- 2.2
Enter Element on position : 12 :- 2.2
Enter Element on position : 20 :- 2.2
Enter Element on position : 21 :- 2.2
Enter Element on position : 22 :- 2.2
********* MENU **********
1]. Enter Matrix
2]. Display
MATRIX
3]. ADD TWO MATRIX
4]. SUBTRACT TWO MATRIX
5].
MULTIPLY TWO MATRIX
Enter Your choice : 2
MATRIX 1 :
Elements in Matrix Are :
1.2 1.2 1.2
1.2 1.2 1.2
1.2 1.2 1.2
MATRIX 2 :
Elements in Matrix Are :
2.2 2.2 2.2
2.2 2.2 2.2
2.2 2.2 2.2
********* MENU **********
1]. Enter Matrix
2]. Display
MATRIX
3]. ADD TWO MATRIX
4]. SUBTRACT TWO MATRIX
5].
MULTIPLY TWO MATRIX
Enter Your choice : 3
Addition of Two Matrix is :
Elements in Matrix Are :
3.4 3.4 3.4
3.4 3.4 3.4
3.4 3.4 3.4
********* MENU **********
1]. Enter Matrix
2]. Display
MATRIX
3]. ADD TWO MATRIX
4]. SUBTRACT TWO MATRIX
5].
MULTIPLY TWO MATRIX
Enter Your choice : 4
Subtraction of Two Matrix is :
Elements in Matrix Are :
-1
-1 -1
-1 -1 -1
-1 -1
-1
*********
MENU **********
1]. Enter Matrix
2]. Display MATRIX
3]. ADD TWO
MATRIX
4]. SUBTRACT TWO MATRIX
5]. MULTIPLY TWO MATRIX
Enter Your choice : 5
Multiplication of Two Matrix is :
Elements in Matrix Are :
6.92
6.92 6.92
6.92 6.92 6.92
6.92
6.92 6.92
==== Matrix DataType
Menu ====
1]. Enter Int matrix
2]. Enter Float matrix
3].
Exit
Enter Your
Choice : 3
*/
---------------------------------------------------
Program 7:
---------------------------------------------------
/*****************************************************************************************************************
*
TITLE :
Design a C++ base class consisting of the data members such as name
of the student,
roll number and subject. The
derived class consists of the data members subject code,
internal assessment and university examination marks. Construct a
virtual base class
for the item name of the
student and roll number. The program should have the
facilities.i) Build a master table ii) List a table iii) Insert a new
entry
iv) Delete old entry v) Edit an entry vi) Search
for a record
ASSIGNMENT NO. :
07
GROUP
: A
ROLL NO.
:
BATCH
:
S
*******************************************************************************************************************/
#include<iostream>
#include<string.h>
using
namespace std;
class Base
{
public:
int rno,imarks,umarks;
static int count();
static
int cnt;
char
nm[15],sub[10];
void
get()
{
cout<<"\n\n\t\t
Enter Student name : ";
cin>>nm;
cout<<"\n\n\t\t Enter Roll No. : ";
cin>>rno;
}
void
disp()
{
cout<<"\n\n\t\t NAME
: "<<nm;
cout<<"\n\n\t\t Roll No : "<<rno;
}
};
int Base::cnt=0;
int
Base::count()
{
cnt=cnt+1;
return(cnt);
}
class Subject:virtual public Base
{
public:
int subcode;
char sub[10];
void
get1()
{
cout<<"\n\n\t\t
Enter Subject Name: ";
cin>>sub;
cout<<"\n\n\t\t Enter Subject Code :
";
cin>>subcode;
}
void disp1()
{
cout<<"\n\n\t\t Subject Name : "<<sub;
cout<<"\n\n\t\t
Subject Code : "<<subcode;
}
};
class Marks:virtual public Base
{
public:
void get2()
{
cout<<"\n\n\t\t Enter internal assessment marks : ";
cin>>imarks;
cout<<"\n\n\t\t
Enter university examination marks :";
cin>>umarks;
}
void disp2()
{
cout<<"\n\n\t\t Internal assessment marks : "<<imarks;
cout<<"\n\n\t\t
University examination marks : "<<umarks;
}
};
class result:public
Subject,Marks
{
public:
void
finalget()
{
get();
get1();
get2();
}
void finaldisp()
{
disp();
disp1();
disp2();
}
};
int
main()
{
result r[50];
Base b[10];
int
ch,n,i,ch1,n1,d,No,count=0,pos;
char
Search[20];
cout<<"\n\n\t\t
============================================================================================";
cout<<"\n\n\t\t
PROGRAM FOR ACCEPTING STUDENT DETAILS USING VIRTUAL BASE CLASS AND
DERIVED CLASS";
cout<<"\n\n\t\t
============================================================================================";
do
{
cout<<"\n\t\t ***************************";
cout<<"\n\t\t\t
MENU ";
cout<<"\n\t\t
***************************";
cout<<"\n\t 1].Accept Data";
cout<<"\n\t 2].List a table "
;
cout<<"\n\t
3].Insert a new entry ";
cout<<"\n\t 4].Delete old entry ";
cout<<"\n\t 5].Edit an entry ";
cout<<"\n\t 6].Search for a
record";
cout<<"\n\t
7]. Exit";
cout<<"\n\n\t\t Enter Your Choice : ";
cin>>ch;
switch(ch)
{
case 1: cout<<"\n\n\t Enter
"<<(count+1)<<" Student details :\n";
r[count].finalget();
count++;
break;
case 2: cout<<"\n\n\t NAME |\t| Roll No
|\t| Subject |\t| Subject code |\t| Internal Marks |\t| University
Marks\n";
for(i=0;i<count;i++)
{
cout<<"\n\t"<<r[i].nm<<" \t
"<<r[i].rno<<" \t "<<r[i].sub<<"
\t "<<r[i].subcode<<" \t "<<r[i].imarks<<"
\t "<<r[i].umarks<<" \n";
}
break;
case 3: cout<<"\n\n\t\t
Enter the position : ";
cin>>pos;
pos=pos-1;
count++;
for(i=pos;i<(count+pos);i++)
{
r[i+1]=r[i];
}
r[pos].finalget();
cout<<"\n\n\t NAME
|\t| Roll No |\t| Subject |\t| Subject code |\t| Internal Marks |\t|
University Marks\n";
for(i=0;i<count;i++)
{
cout<<"\n\t"<<r[i].nm<<"
\t "<<r[i].rno<<" \t "<<r[i].sub<<"
\t "<<r[i].subcode<<" \t "<<r[i].imarks<<"
\t "<<r[i].umarks<<" \n";
}
break;
case 4:cout<<"\n\nEnter The Position
you want To Delete : ";
cin>>No;
No=No-1;
for(i=0;i<count;i++)
{
if(i==No)
{
for(i=No;i<count;i++)
{
r[i]=r[i+1];
}
n=n-1;
cout<<"\n\nRecord Successfully Deleted !!!\n";
count--;
break;
}
}
break;
case 5:cout<<"\n\nEnter Name To Want to
Edit Database : ";
cin>>Search;
for(i=0;i<count;i++)
{
if(strcmp(r[i].nm,Search)==0)
{
r[i].finalget();
cout<<"\n\n\t NAME |\t| Roll No |\t| Subject |\t| Subject
code |\t| Internal Marks |\t| University Marks\n";
cout<<"\n\t"<<r[i].nm<<"
\t "<<r[i].rno<<" \t "<<r[i].sub<<"
\t "<<r[i].subcode<<" \t "<<r[i].imarks<<"
\t "<<r[i].umarks<<" \n";
}
}
break;
case 6:cout<<"\n\nEnter Name To Search Database : ";
cin>>Search;
for(i=0;i<count;i++)
{
if(strcmp(r[i].nm,Search)==0)
{
cout<<"\n\nRecord Found !!!";
cout<<"\n\nRecord Position : "<<i+1;
cout<<"\n\nDetails\n-------------";
cout<<"\n\n\t NAME |\t| Roll No |\t| Subject |\t|
Subject code |\t| Internal Marks |\t| University Marks\n";
cout<<"\n\t"<<r[i].nm<<" \t
"<<r[i].rno<<" \t "<<r[i].sub<<"
\t "<<r[i].subcode<<" \t "<<r[i].imarks<<"
\t "<<r[i].umarks<<" \n";
}
}
break;
case 7:return 1;
break;
}
}while(ch!=7);
return
0;
}
/****************************************************************************************
*
OUTPUT
****************************************************************************************
============================================================================================
PROGRAM FOR
ACCEPTING STUDENT DETAILS USING VIRTUAL BASE CLASS AND DERIVED
CLASS
============================================================================================
***************************
MENU
***************************
1].Accept
Data
2].List a table
3].Insert a new entry
4].Delete old
entry
5].Edit an entry
6].Search for a record
7].
Exit
Enter Your
Choice : 1
Enter 1 Student
details :
Enter
Student name : Aman
Enter Roll No. : 1
Enter Subject Name: maths
Enter Subject Code : 0025
Enter internal assessment marks : 56
Enter university examination marks :78
***************************
MENU
***************************
1].Accept
Data
2].List a table
3].Insert a new entry
4].Delete old
entry
5].Edit an entry
6].Search for a record
7].
Exit
Enter Your
Choice : 2
NAME |
| Roll No | | Subject | | Subject
code | | Internal Marks | |
University Marks
Aman 1
maths 25
56 78
***************************
MENU
***************************
1].Accept Data
2].List a table
3].Insert a new entry
4].Delete old
entry
5].Edit an entry
6].Search for a record
7].
Exit
Enter Your
Choice : 3
Enter
the position : 1
Enter Student name : umesh
Enter Roll No. : 2
Enter Subject Name: Dsps
Enter Subject Code : 0654
Enter internal assessment marks : 23
Enter university examination marks :45
NAME | | Roll No | |
Subject | | Subject code | |
Internal Marks | | University Marks
umesh 2 Dsps
654 23 45
Aman 1 maths
25 56 78
***************************
MENU
***************************
1].Accept
Data
2].List a table
3].Insert a new entry
4].Delete old
entry
5].Edit an entry
6].Search for a record
7].
Exit
Enter Your
Choice : 3
Enter
the position : 2
Enter Student name : pranav
Enter Roll No. : 3
Enter Subject Name: Osa
Enter Subject Code : 0647
Enter internal assessment marks : 89
Enter university examination marks :75
NAME | | Roll No | |
Subject | | Subject code | |
Internal Marks | | University Marks
umesh 2
Dsps
654
23
45
pranav 3
Osa 647
89 75
Aman
1 maths
25 56 78
***************************
MENU
***************************
1].Accept
Data
2].List a table
3].Insert a new entry
4].Delete old
entry
5].Edit an entry
6].Search for a record
7].
Exit
Enter Your
Choice : 4
Enter The Position you want To Delete :
2
Record Successfully Deleted !!!
***************************
MENU
***************************
1].Accept
Data
2].List a table
3].Insert a new entry
4].Delete old
entry
5].Edit an entry
6].Search for a record
7].
Exit
Enter Your
Choice : 2
NAME |
| Roll No | | Subject | | Subject
code | | Internal Marks | |
University Marks
umesh
2
Dsps 654
23
45
Aman
1
maths 25
56
78
***************************
MENU
***************************
1].Accept Data
2].List a table
3].Insert a new entry
4].Delete old
entry
5].Edit an entry
6].Search for a record
7].
Exit
Enter Your
Choice : 5
Enter Name To Want to Edit Database :
Aman
Enter
Student name : AmanB
Enter Roll No. : 3
Enter Subject Name: MIT
Enter Subject Code : 4875
Enter internal assessment marks : 56
Enter university examination marks :78
NAME | | Roll No | |
Subject | | Subject code | |
Internal Marks | | University Marks
AmanB 3 MIT
4875 56 78
***************************
MENU
***************************
1].Accept
Data
2].List a table
3].Insert a new entry
4].Delete old
entry
5].Edit an entry
6].Search for a record
7].
Exit
Enter Your
Choice : 2
NAME |
| Roll No | | Subject | | Subject
code | | Internal Marks | |
University Marks
umesh
2 Dsps 654
23 45
AmanB 3 MIT
4875 56 78
***************************
MENU
***************************
1].Accept
Data
2].List a table
3].Insert a new entry
4].Delete old
entry
5].Edit an entry
6].Search for a record
7].
Exit
Enter Your
Choice : 6
Enter Name To Search Database : AmanB
Record
Found !!!
Record Position : 2
Details
-------------
NAME | | Roll No | |
Subject | | Subject code | |
Internal Marks | | University Marks
AmanB 3 MIT
4875 56 78
***************************
MENU
***************************
1].Accept
Data
2].List a table
3].Insert a new entry
4].Delete old
entry
5].Edit an entry
6].Search for a record
7].
Exit
Enter Your
Choice : 7
*/
---------------------------------------------------
Program 8:
---------------------------------------------------
=====================================================================
Group
:A
Assignment No:8
Title:Create a C++ class named Television
that has data members to hold
the model number and the screen size in inches, and the
price. Member functions include overloade insertion and
extraction operators. If more than four digits are entered for
the model, if the screen size is smaller than 12 or greater than
70 inches, or if the price is negative or over $5000 then throw
an integer. Write a main() function that instantiates a
television object, allows user to enter data and displays the
data members .If an exception is caught,replace all the data
member values with zero values.
Roll No:
class:SE(Computer)
Batch:
S
=====================================================================
PROGRAM:
#include
<iostream>
#include<string.h>
using namespace
std;
class tel
{
public:
char *modno;
float price,size;
public
:
tel()
{
modno =new char[20];
strcpy(modno,"0");
price=0;
size=0;
}
void display();
friend istream &operator >> (istream
&in,tel &t1)
{
cout<<"\nEnter Model
Number: ";
in>>t1.modno;
cout<<"\nEnter Total Prize: ";
in>>t1.price;
cout<<"\nEnter
Display size in inches: ";
in>>t1.size;
return in;
}
friend ostream
&operator << (ostream &out,tel &t1)
{
tel t;
int s=strlen(t1.modno);
try
{
if(s>4)
throw 1;
if(t1.size<7||t1.size>12)
throw 2;
if(t1.price>5000||t1.price<0)
throw 3;
else
{
t1.display();
}
}
catch(int x)
{
if(x==1)
cout<<"Mode no to large than 4 digits
!!!";
if(x==2)
cout<<"Size should
be less than 7 inches or greater than 12 inches !!! ";
else
if(x==3)
cout<<"Price
is greater than 5000 or negative";
t.display();
}
return out;
}
};
void tel::display()
{
cout<<"\nModel Number is: ";
cout<<modno;
cout<<"\nTotal Prize is: ";
cout<<price;
cout<<"\nDisplay size (inches)is: ";
cout<<size;
}
int main()
{
int ch;
tel te;
do
{
cout<<"\n\n=====Information about
Television======\n";
cout<<"\n1.Insert Information";
cout<<"\n2.Display Information";
cout<<"\n3.Exit";
cout<<"\n\nEnter your choice :";
cin>>ch;
switch(ch)
{
case 1:cout<<"\nEnter the Information
about Television \n";
cin>>te;
break;
case 2:cout<<"\n------Details about
Television------\n";
cout<<te;
break;
case 3: return 0;
}
}while(1);
}
================================================================
OUTPUT
================================================================
=====Information
about Television======
1.Insert Information
2.Display
Information
3.Exit
Enter your choice :1
Enter the
Information about Television
Enter Model Number: Hx23
Enter
Total Prize: 4500
Enter Display size in inches:
10
=====Information about Television======
1.Insert
Information
2.Display Information
3.Exit
Enter your
choice :2
------Details about Television------
Model
Number is: Hx23
Total Prize is: 4500
Display size (inches)is:
10
=====Information about Television======
1.Insert
Information
2.Display Information
3.Exit
Enter your
choice :1
Enter the Information about Television
Enter
Model Number: 12W344
Enter Total Prize: 5000
Enter
Display size in inches: 11
=====Information about
Television======
1.Insert Information
2.Display
Information
3.Exit
Enter your choice :2
------Details
about Television------
Mode no to large than 4 digits !!!
Model
Number is: 0
Total Prize is: 0
Display size (inches)is:
0
=====Information about Television======
1.Insert
Information
2.Display Information
3.Exit
Enter your
choice :1
Enter the Information about Television
Enter
Model Number: EX12
Enter Total Prize: 5500
Enter
Display size in inches: 10
=====Information about
Television======
1.Insert Information
2.Display
Information
3.Exit
Enter your choice :2
------Details
about Television------
Price is greater than 5000 or
negative
Model Number is: 0
Total Prize is: 0
Display size
(inches)is: 0
=====Information about
Television======
1.Insert Information
2.Display
Information
3.Exit
Enter your choice :1
Enter the
Information about Television
Enter Model Number: WF12
Enter
Total Prize: 4400
Enter Display size in inches:
15
=====Information about Television======
1.Insert
Information
2.Display Information
3.Exit
Enter your
choice :2
------Details about Television------
Size should
be less than 7 inches or greater than 12 inches !!!
Model Number
is: 0
Total Prize is: 0
Display size (inches)is:
0
=====Information about Television======
1.Insert
Information
2.Display Information
3.Exit
Enter your
choice :3
---------------------------------------------------
Program 9:
---------------------------------------------------
/***************************************************************************************************************
TITLE
:
Using multi-core programming implement POSIX-spawn() function to
create a
process
ASSIGNMENT NO.
: 11
GROUP
: B
ROLL
NO. :
BATCH
:
S1
*****************************************************************************************************************/
#
include<iostream>
#include <stdlib.h>
#include
<pthread.h>
using namespace std;
void *function1(void
*n)
{
long num;
num=(long)n;
long fact=1;
for(int
i=1;i<=num;i++)
fact = fact*i;
cout<<"The
Factorial of "<<num<<"is=
"<<fact;
cout<<"\n
_____________________________\n";
pthread_exit(NULL);
}
void
* function2(void *n)
{
long num;
num=(long)n;
int
x=0,y=1,z;
cout<<"\n \nThe fibonacci sequence of
limit= "<<num<<"is....\n";
cout<<"
"<<x;
cout<<" "<<y;
for(int
i=0;i<num-2;i++)
{
z=x+y;
cout<<"
"<<z;
x=y;
y=z;
}
cout<<"\n";
pthread_exit(NULL);
}
int
main(int argc,char *argv[])
{
pthread_t thread1,thread2;
int
n1,n2;
n1=7;
n2=15;
pthread_create(&thread1,NULL,function1,(void
*)n1);
pthread_create(&thread2,NULL,function2,(void
*)n2);
pthread_join(thread1,NULL);
pthread_join(thread2,NULL);
pthread_exit(NULL);
}
/*
-----------------------
OUTPUT
-----------------------
elearninglab-13@elearninglab03-OptiPlex-390:~/Downloads$
g++ calltasks.cpp -o calltasks
-lpthread
elearninglab-13@elearninglab03-OptiPlex-390:~/Downloads$
./calltasks
The Factorial of
The fibonacci sequence of
limit= 157is=
5040
_____________________________
is....
0 1 1
2 3 5 8 13 21 34 55 89 144 233
377
elearninglab-13@elearninglab03-OptiPlex-390:~/Downloads$
*/
---------------------------------------------------
Program 10:
---------------------------------------------------
#include<iostream>
#include<string>
#include<spawn.h>
#include<sys/wait.h>
using
namespace std;
int main(void)
{
int
pid1,pid2,pid3;
char str1[]="mkdir";
char str2[]="Neha";
char str3[]="pwd";
char str4[]="ls";
char*
spawnedArgs1[]={str1,str2,(char *)0};
char*
spawnedArgs2[]={str3,(char *)0};
char*
spawnedArgs3[]={str4,(char *)0};
int
sta1=posix_spawnp(&pid1,"/bin/mkdir",NULL,NULL,spawnedArgs1,NULL);
wait(&sta1);
int
sta2=posix_spawnp(&pid2,"/bin/pwd",NULL,NULL,spawnedArgs2,NULL);
int sta3=posix_spawnp(&pid3,"/bin/ls",NULL,NULL,spawnedArgs3,NULL);
cout<<"\n Task: Creating 'Neha'
Directory....."<<"\n Pid :"<<pid1<<"\n
Posix Spawn Status :"<<sta1;
cout<<"\n
Task: Displaying The Path Of 'Neha' Directory....."<<"\n
Pid :"<<pid2<<"\n Posix Spawn Status
:"<<sta2;
cout<<"\n Task: Displaying
List Of Processes ........"<<"\n Pid :"<<pid3<<"\n
Posix Spawn Status :"<<sta3;
wait(&sta2);
wait(&sta3);
}
/*
OUTPUT
elearninglab-13@elearninglab03-OptiPlex-390:~$ cd
Desktop/
elearninglab-13@elearninglab03-OptiPlex-390:~/Desktop$
g++ p10.cpp -o
p10
elearninglab-13@elearninglab03-OptiPlex-390:~/Desktop$
./p10
Task: Creating 'Neha' Directory.....
Pid
:4058
Posix Spawn Status
:0
/home/elearninglab-13/Desktop
Task: Displaying The
Path Of 'Neha' Directory.....
Pid :4059
Posix Spawn
Status :0
Task: Displaying List Of Processes ........
Pid
:4060
ASSIGN_8.cpp
Weather_report.cpp~ be_39
readwrite.c~
BE29
a.cpp
be_39.zip
ring
Makefile.add
a.out c.class
s.class
Neha
a6
c.java
s.java
Untitled Document abc
c.java~
se68
Untitled Document 2 add.h
example.c
shape.class
Untitled Document 2~ add.x
example.c~
shape.java
Untitled Document 3 add_client.c
example.html~
shape.java~
Untitled Document 3~ add_clnt.c
p10
sm.c
Untitled Document 4 add_server.c
p10.cpp
software11
Untitled Document 4~ add_svc.c
p10.cpp~
test.c~
Untitled Document 5~ add_xdr.c
pr10
u
Untitled Document~
as2.odt
readerwriterproble.c u.cpp
Untitled Folder
asS1
readerwriterproble.c~ u.cpp~
Weather_report.cpp
asS1~
readwrite.c
u.o
elearninglab-13@elearninglab03-OptiPlex-390:~/Desktop$
*/
---------------------------------------------------
Program 12:
---------------------------------------------------
# include<iostream>
#include <string>
#include
<spawn.h>
#include <sys/wait.h>
using namespace
std;
int main (int argc,char *argv[],char *envp[])
{
int
sta;
pid_t pid1,pid2;
int val1 =
posix_spawnp(&pid1,"calltasks",NULL,NULL,argv,envp);
wait(&sta);
int
val2 =
posix_spawnp(&pid2,"calltasks",NULL,NULL,argv,envp);
cout<<"Task:
in Parent
Processes"<<val1;
wait(&sta);
return(0);
}
--------------
#include<pthread.h>
#include<stdlib.h>
#include<iostream>
#include
<unistd.h> //
std::this_thread::sleep_for
using namespace std;
#define
Max 10
void *Myfun(void *data)
{
int *val;
val=
static_cast<int*>(data);
for(int j=0;j<*val;j++)
cout<<"\n
Iterations "<<j<<endl;
return
NULL;
}
int main(int argc,char
*argv[])
{
pthread_t threadid[Max];
int
i,n;
n=atoi(argv[1]);
if(n>Max)
{
cout<<"Can
not create more than
"<<Max<<"threads";
n=Max;
}
for(i=0;i<n;i++)
{
pthread_create(&threadid[i],NULL,Myfun,&n);
cout<<"created
new thread. Threadid =
"<<threadid[i]<<endl;
sleep(1);
}
for(i=0;i<n;i++)
{
pthread_join(threadid[i],NULL);
}
return
0;
}
elearninglab-13@elearninglab03-OptiPlex-390:~$ g++
treadcmd.cpp -lpthread -o
t1
elearninglab-13@elearninglab03-OptiPlex-390:~$ ./t1 3
created
new thread. Threadid =
Iterations
0140270930933504
Iterations 1
Iterations
2
created new thread. Threadid = 140270922540800
Iterations
0
Iterations 1
Iterations
2
created new thread. Threadid = 140270914148096
Iterations
0
Iterations 1
Iterations
2
elearninglab-13@elearninglab03-OptiPlex-390:~$ ./t1 5
created
new thread. Threadid = 140589670897408
Iterations
0
Iterations 1
Iterations
2
Iterations 3
Iterations
4
created new thread. Threadid = 140589662504704
Iterations
0
Iterations 1
Iterations
2
Iterations 3
Iterations
4
created new thread. Threadid = 140589654112000
Iterations
0
Iterations 1
Iterations
2
Iterations 3
Iterations
4
created new thread. Threadid = 140589645719296
Iterations
0
Iterations 1
Iterations
2
Iterations 3
Iterations
4
created new thread. Threadid = 140589637326592
Iterations
0
Iterations 1
Iterations
2
Iterations 3
Iterations
4
elearninglab-13@elearninglab03-OptiPlex-390:~$
---------------------------------------------------
Program 13:
---------------------------------------------------
=================================================================================
Assignment
No.:-
Batch:-
Roll No.:-
Aim:-Implement C++/Java/Python
program to create a base class called shape. Use this
class to store two double type values that could be used to compute
the area of
figures. Derive two specific
classes called function get_data() to initialize base class
data members and another member function display_area() to compute
and display
the area of figures. Make
classes to suit their requirements.
Using
these three classes, design a program that will accept dimension of a
triangle or
a rectangle interactively,
and display the area.
Remember the two
values given as input will be treated as lengths of two sides in the
case of rectangles, and as base and
height in the case of triangles, and used as
follows:
Area of rectangle= x*y
Area of triangle
=1/2*x*y
=================================================================================
import
java.io.BufferedReader;
import java.io.IOException;
import
java.io.InputStreamReader;
import java.util.Scanner;
abstract
class figure
{
double x,y;
void
getdata (double length,double breadth)
{
x=length;
y=breadth;
}
abstract void
display_area();
}
class rectangle extends figure
{
public void display_area()
{
double area;
area=(x*y);
System.out.println("\n The Area Of Rectangle Is
:"+area+"Sq. Units");
}
}
class
triangle extends figure
{
public void
display_area()
{
double area;
area=0.5*(x*y);
System.out.println("\n The Area Of Triangle Is
:"+area+"Sq.Units");
}
}
public class shape
{
public static void main(String[] args) throws NumberFormatException,
IOException
{
int choice;
Scanner input = new Scanner(System.in);
do
{
System.out.println("\n\t\t ****** Main Menu ****** ");
System.out.println("\n\t 1. Area Of Rectangle");
System.out.println("\n\t 2. Area Of Triangle");
System.out.println("\n\t 3. Exit");
System.out.println("\n\t
Enter You Choice :");
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
choice=Integer.parseInt(br.readLine());
switch(choice)
{
case 1:
System.out.println("\n Enter the value of length :");
double
a=input.nextDouble();
System.out.println("\n Enter the value of breadth
:");
double
b=input.nextDouble();
rectangle r=new
rectangle();
r.getdata(a,b);
r.display_area();
break;
case 2:
System.out.println("\n Enter the value of base :");
double
c=input.nextDouble();
System.out.println("\n Enter the value of height :");
double
d=input.nextDouble();
triangle t=new
triangle();
t.getdata(c,d);
t.display_area();
break;
case 3:
System.exit(0);
break;
default:
System.out.println("Error");
break;
}
}
while(choice!=3);
}
}
/*
OUTPUT
****** Main Menu ******
1. Area Of
Rectangle
2. Area Of Triangle
3. Exit
Enter You Choice
:
1
Enter the value of length :
12
Enter
the value of breadth :
12
The Area Of Rectangle Is
:144.0Sq. Units
******
Main Menu ******
1. Area Of Rectangle
2. Area Of Triangle
3. Exit
Enter You Choice :
2
Enter the value of base
:
2
Enter the value of height :
5
The
Area Of Triangle Is :5.0Sq.Units
****** Main Menu ******
1. Area Of
Rectangle
2. Area Of Triangle
3. Exit
Enter You Choice :
3
*/
No comments:
Post a Comment