---------------------------------------------------
Program 1:
---------------------------------------------------
//============================================================================
// ROLL NO : 73
// CLASS : SE(COMPUTER)
// BATCH : S4
// 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 <iostream>
using namespace std;
class wheather_report
{
public:
int dom,avg;
float htemp,ltemp;
int amount_rain,amount_snow;
wheather_report()
{
dom=99;
htemp=999;
ltemp=-999;
amount_snow=0;
amount_rain=0;
}
void domnt();
void hghtemp();
void lowtemp();
void amountof_rain();
void amountof_snow();
void enter_data();
void display_data();
};
void wheather_report::domnt()
{
cout<<"\n\t\t Enter DATE OF MONTH: ";
cin>>dom;
}
void wheather_report::hghtemp()
{
cout<<"\n\t\t Enter HIGH TEMPERATURE: ";
cin>>htemp;
}
void wheather_report::lowtemp()
{
cout<<"\n\t\t Enter LOW TEMPERATURE: ";
cin>>ltemp;
}
void wheather_report::amountof_rain()
{
cout<<"\n\t\t Enter AMOUNT OF RAINFALL: ";
cin>>amount_rain;
}
void wheather_report::amountof_snow()
{
cout<<"\n\t\t Enter AMOUNT OF SNOW FALL: ";
cin>>amount_snow;
}
void wheather_report::enter_data()
{
domnt();
hghtemp();
lowtemp();
amountof_rain();
amountof_snow();
}
void wheather_report::display_data()
{
cout<<"\n\t"<<dom<<"\t|\t"<<htemp<<"\t|\t"<<ltemp<<"\t|\t"<<amount_rain<<"\t|\t"<<amount_snow<<"\n";
}
int main()
{
wheather_report wr[31];
int ch,i,sumhtemp=0,sumltemp=0,sumrain=0,sumsnow=0,cnt=0;
float avghtemp=0,avgltemp=0,avgrain=0,avgsnow=0;
cout<<"\n\n\t\t ******* PROGRAM FOR WHEATHER REPORT ********";
do
{
cout<<"\n\n\t\t ***** MENU ****";
cout<<"\n\n\t\t 1] . Accept data";
cout<<"\n\t\t 2] . Display data";
cout<<"\n\t\t 3] . Exit";
cout<<"\n\t\t Enter your choice : ";
cin>>ch;
switch(ch)
{
case 1:
wr[cnt].enter_data();
sumhtemp= sumhtemp + wr[cnt].htemp;
sumltemp= sumltemp + wr[cnt].ltemp;
sumrain= sumrain + wr[cnt].amount_rain;
sumsnow= sumsnow + wr[cnt].amount_snow;
cnt++;
break;
case 2: cout<<"\n\tDOM\t| HIGHTEMP\t| LOWTEMP\t| AMOUNT_RAIN\t| AMOUNT_SNOW \n";
for(i=0;i<cnt;i++)
{
wr[i].display_data();
}
avghtemp=(float)sumhtemp/cnt;
avgltemp=(float)sumltemp/cnt;
avgrain=(float)sumrain/cnt;
avgsnow=(float)sumsnow/cnt;
cout<<"\n Average is\t|\t"<<avghtemp<<"\t|\t"<<avgltemp<<"\t|\t"<<avgrain<<"\t|\t"<<avgsnow<<"\n";
break;
case 3: return 1;
}
}while(ch!=3);
return 0;
}
/////*************OUTPUT************////
/*
******* PROGRAM FOR WHEATHER REPORT ********
***** MENU ****
1] . Accept data
2] . Display data
3] . Exit
Enter your choice : 1
Enter DATE OF MONTH: 1
Enter HIGH TEMPERATURE: 55
Enter LOW TEMPERATURE: 44
Enter AMOUNT OF RAINFALL: 3
Enter AMOUNT OF SNOW FALL: 4
***** MENU ****
1] . Accept data
2] . Display data
3] . Exit
Enter your choice : 1
Enter DATE OF MONTH: 2
Enter HIGH TEMPERATURE: 55
Enter LOW TEMPERATURE: 10
Enter AMOUNT OF RAINFALL: 3
Enter AMOUNT OF SNOW FALL: 6
***** MENU ****
1] . Accept data
2] . Display data
3] . Exit
Enter your choice : 1
Enter DATE OF MONTH: 3
Enter HIGH TEMPERATURE: 44
Enter LOW TEMPERATURE: 9
Enter AMOUNT OF RAINFALL: 2
Enter AMOUNT OF SNOW FALL: 8
***** MENU ****
1] . Accept data
2] . Display data
3] . Exit
Enter your choice : 1
Enter DATE OF MONTH: 4
Enter HIGH TEMPERATURE: 55
Enter LOW TEMPERATURE: 11
Enter AMOUNT OF RAINFALL: 6
Enter AMOUNT OF SNOW FALL: 7
***** MENU ****
1] . Accept data
2] . Display data
3] . Exit
Enter your choice : 1
Enter DATE OF MONTH: 5
Enter HIGH TEMPERATURE: 60
Enter LOW TEMPERATURE: 12
Enter AMOUNT OF RAINFALL: 2
Enter AMOUNT OF SNOW FALL: 9
***** MENU ****
1] . Accept data
2] . Display data
3] . Exit
Enter your choice : 1
Enter DATE OF MONTH: 6
Enter HIGH TEMPERATURE: 33
Enter LOW TEMPERATURE: 19
Enter AMOUNT OF RAINFALL: 10
Enter AMOUNT OF SNOW FALL: 16
***** MENU ****
1] . Accept data
2] . Display data
3] . Exit
Enter your choice : 1
Enter DATE OF MONTH: 7
Enter HIGH TEMPERATURE: 44
Enter LOW TEMPERATURE: 12
Enter AMOUNT OF RAINFALL: 5
Enter AMOUNT OF SNOW FALL: 9
***** MENU ****
1] . Accept data
2] . Display data
3] . Exit
Enter your choice : 1
Enter DATE OF MONTH: 8
Enter HIGH TEMPERATURE: 55
Enter LOW TEMPERATURE: 13
Enter AMOUNT OF RAINFALL: 10
Enter AMOUNT OF SNOW FALL: 9
***** MENU ****
1] . Accept data
2] . Display data
3] . Exit
Enter your choice : 1
Enter DATE OF MONTH: 9
Enter HIGH TEMPERATURE: 43
Enter LOW TEMPERATURE: 22
Enter AMOUNT OF RAINFALL: 6
Enter AMOUNT OF SNOW FALL: 8
***** MENU ****
1] . Accept data
2] . Display data
3] . Exit
Enter your choice : 1
Enter DATE OF MONTH: 10
Enter HIGH TEMPERATURE: 30
Enter LOW TEMPERATURE: 22
Enter AMOUNT OF RAINFALL: 6
Enter AMOUNT OF SNOW FALL: 8
***** MENU ****
1] . Accept data
2] . Display data
3] . Exit
Enter your choice : 1
Enter DATE OF MONTH: 11
Enter HIGH TEMPERATURE: 35
Enter LOW TEMPERATURE: 10
Enter AMOUNT OF RAINFALL: 5
Enter AMOUNT OF SNOW FALL: 4
***** MENU ****
1] . Accept data
2] . Display data
3] . Exit
Enter your choice : 1
Enter DATE OF MONTH: 12
Enter HIGH TEMPERATURE: 36
Enter LOW TEMPERATURE: 28
Enter AMOUNT OF RAINFALL: 6
Enter AMOUNT OF SNOW FALL: 8
***** MENU ****
1] . Accept data
2] . Display data
3] . Exit
Enter your choice : 1
Enter DATE OF MONTH: 13
Enter HIGH TEMPERATURE: 40
Enter LOW TEMPERATURE: 20
Enter AMOUNT OF RAINFALL: 5
Enter AMOUNT OF SNOW FALL: 8
***** MENU ****
1] . Accept data
2] . Display data
3] . Exit
Enter your choice : 1
Enter DATE OF MONTH: 14
Enter HIGH TEMPERATURE: 42
Enter LOW TEMPERATURE: 19
Enter AMOUNT OF RAINFALL: 10
Enter AMOUNT OF SNOW FALL: 19
***** MENU ****
1] . Accept data
2] . Display data
3] . Exit
Enter your choice : 1
Enter DATE OF MONTH: 15
Enter HIGH TEMPERATURE: 40
Enter LOW TEMPERATURE: 10
Enter AMOUNT OF RAINFALL: 10
Enter AMOUNT OF SNOW FALL: 10
***** MENU ****
1] . Accept data
2] . Display data
3] . Exit
Enter your choice : 1
Enter DATE OF MONTH: 16
Enter HIGH TEMPERATURE: 32
Enter LOW TEMPERATURE: 13
Enter AMOUNT OF RAINFALL: 20
Enter AMOUNT OF SNOW FALL: 10
***** MENU ****
1] . Accept data
2] . Display data
3] . Exit
Enter your choice : 1
Enter DATE OF MONTH: 17
Enter HIGH TEMPERATURE: 36
Enter LOW TEMPERATURE: 10
Enter AMOUNT OF RAINFALL: 25
Enter AMOUNT OF SNOW FALL: 23
***** MENU ****
1] . Accept data
2] . Display data
3] . Exit
Enter your choice : 1
Enter DATE OF MONTH: 18
Enter HIGH TEMPERATURE: 39
Enter LOW TEMPERATURE: 15
Enter AMOUNT OF RAINFALL: 20
Enter AMOUNT OF SNOW FALL: 10
***** MENU ****
1] . Accept data
2] . Display data
3] . Exit
Enter your choice : 1
Enter DATE OF MONTH: 19
Enter HIGH TEMPERATURE: 30
Enter LOW TEMPERATURE: 40
Enter AMOUNT OF RAINFALL: 25
Enter AMOUNT OF SNOW FALL: 20
***** MENU ****
1] . Accept data
2] . Display data
3] . Exit
Enter your choice : 1
Enter DATE OF MONTH: 20
Enter HIGH TEMPERATURE: 50
Enter LOW TEMPERATURE: 22
Enter AMOUNT OF RAINFALL: 16
Enter AMOUNT OF SNOW FALL: 13
***** MENU ****
1] . Accept data
2] . Display data
3] . Exit
Enter your choice : 1
Enter DATE OF MONTH: 21
Enter HIGH TEMPERATURE: 33
Enter LOW TEMPERATURE: 11
Enter AMOUNT OF RAINFALL: 5
Enter AMOUNT OF SNOW FALL: 8
***** MENU ****
1] . Accept data
2] . Display data
3] . Exit
Enter your choice : 1
Enter DATE OF MONTH: 22
Enter HIGH TEMPERATURE: 35
Enter LOW TEMPERATURE: 12
Enter AMOUNT OF RAINFALL: 8
Enter AMOUNT OF SNOW FALL: 9
***** MENU ****
1] . Accept data
2] . Display data
3] . Exit
Enter your choice : 1
Enter DATE OF MONTH: 23
Enter HIGH TEMPERATURE: 32
Enter LOW TEMPERATURE: 15
Enter AMOUNT OF RAINFALL: 9
Enter AMOUNT OF SNOW FALL: 10
***** MENU ****
1] . Accept data
2] . Display data
3] . Exit
Enter your choice : 1
Enter DATE OF MONTH: 24
Enter HIGH TEMPERATURE: 30
Enter LOW TEMPERATURE: 20
Enter AMOUNT OF RAINFALL: 10
Enter AMOUNT OF SNOW FALL: 0
***** MENU ****
1] . Accept data
2] . Display data
3] . Exit
Enter your choice : 1
Enter DATE OF MONTH: 25
Enter HIGH TEMPERATURE: 45
Enter LOW TEMPERATURE: 10
Enter AMOUNT OF RAINFALL: 2
Enter AMOUNT OF SNOW FALL: 5
***** MENU ****
1] . Accept data
2] . Display data
3] . Exit
Enter your choice : 1
Enter DATE OF MONTH: 26
Enter HIGH TEMPERATURE: 45
Enter LOW TEMPERATURE: 10
Enter AMOUNT OF RAINFALL: 2
Enter AMOUNT OF SNOW FALL: 6
***** MENU ****
1] . Accept data
2] . Display data
3] . Exit
Enter your choice : 1
Enter DATE OF MONTH: 27
Enter HIGH TEMPERATURE: 30
Enter LOW TEMPERATURE: 10
Enter AMOUNT OF RAINFALL: 20
Enter AMOUNT OF SNOW FALL: 10
***** MENU ****
1] . Accept data
2] . Display data
3] . Exit
Enter your choice : 1
Enter DATE OF MONTH: 28
Enter HIGH TEMPERATURE: 20
Enter LOW TEMPERATURE: 10
Enter AMOUNT OF RAINFALL: 10
Enter AMOUNT OF SNOW FALL: 3
***** MENU ****
1] . Accept data
2] . Display data
3] . Exit
Enter your choice : 1
Enter DATE OF MONTH: 29
Enter HIGH TEMPERATURE: 50
Enter LOW TEMPERATURE: 10
Enter AMOUNT OF RAINFALL: 21
Enter AMOUNT OF SNOW FALL: 3
***** MENU ****
1] . Accept data
2] . Display data
3] . Exit
Enter your choice : 1
Enter DATE OF MONTH: 30
Enter HIGH TEMPERATURE: 45
Enter LOW TEMPERATURE: 10
Enter AMOUNT OF RAINFALL: 2
Enter AMOUNT OF SNOW FALL: 3
***** MENU ****
1] . Accept data
2] . Display data
3] . Exit
Enter your choice : 2
DOM | HIGHTEMP | LOWTEMP | AMOUNT_RAIN | AMOUNT_SNOW
1 | 55 | 44 | 3 | 4
2 | 55 | 10 | 3 | 6
3 | 44 | 9 | 2 | 8
4 | 55 | 11 | 6 | 7
5 | 60 | 12 | 2 | 9
6 | 33 | 19 | 10 | 16
7 | 44 | 12 | 5 | 9
8 | 55 | 13 | 10 | 9
9 | 43 | 22 | 6 | 8
10 | 30 | 22 | 6 | 8
11 | 35 | 10 | 5 | 4
12 | 36 | 28 | 6 | 8
13 | 40 | 20 | 5 | 8
14 | 42 | 19 | 10 | 19
15 | 40 | 10 | 10 | 10
16 | 32 | 13 | 20 | 10
17 | 36 | 10 | 25 | 23
18 | 39 | 15 | 20 | 10
19 | 30 | 40 | 25 | 20
20 | 50 | 22 | 16 | 13
21 | 33 | 11 | 5 | 8
22 | 35 | 12 | 8 | 9
23 | 32 | 15 | 9 | 10
24 | 30 | 20 | 10 | 0
25 | 45 | 10 | 2 | 5
26 | 45 | 10 | 2 | 6
27 | 30 | 10 | 20 | 10
28 | 20 | 10 | 10 | 3
29 | 50 | 10 | 21 | 3
30 | 45 | 10 | 2 | 3
Average is | 40.6333 | 15.9667 | 9.46667 | 8.86667
***** MENU ****
1] . Accept data
2] . Display data
3] . Exit
Enter your choice : 3
*/
---------------------------------------------------
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. : 60
BATCH : S4
===============================================================================================================*/
#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 : S4
// 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::Navin
Enter the address:Deolali
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: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: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: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: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 : navin
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 : navin
Enter String : waghwani
Concatenation is : navinwaghwani
******** 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 : navin
Reverse of string is : nivan
******** 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 : navin
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 : navin
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 : navin
Enter String : navin
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 : navin
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 : navin
navin
******** 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 : navin
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
navin 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
navin 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
navin 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
navin 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 : navin
Enter Student name : NavinW
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
NavinW 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
NavinW 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 : NavinW
Record Found !!!
Record Position : 2
Details
-------------
NAME | | Roll No | | Subject | | Subject code | | Internal Marks | | University Marks
NavinW 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 : S4
*****************************************************************************************************************/
# 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 ass4 readerwriterproble.c~ u.cpp~
Weather_report.cpp ass4~ readwrite.c u.o
elearninglab-13@elearninglab03-OptiPlex-390:~/Desktop$
*/
---------------------------------------------------
Program 11:
---------------------------------------------------
---------------------------------------------------
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