/* Slip no : 29_1 Write a C++
program to find maximum of two integer numbers and two float numbers
by using function template.*/
#include<conio.h>
#include<iostream.h>
template<class
T>
T max(T n1,T n2)
{
if(n1>n2)
return
n1;
else
return
n2;
}
void main()
{ int
no1,no2;
float
no3,no4;
clrscr();
cout<<"\n
Enter 2 interger no : ";
cin>>no1>>no2;
cout<<"\n
no1 = "<<no1 <<"\t no2 = "<<no2;
cout<<"\n
maximum = "<<max(no1,no2);
cout<<"\n
Enter 2 float no : ";
cin>>no3>>no4;
cout<<"\n
no1 = "<<no3 <<"\t no2 = "<<no4;
cout<<"\n
maximum = "<<max(no3,no4);
getch();
}
/* Slip no : 29_2 Create a class
for inventory of Mobile containing Model_Number,
Company_Name, Price, Stock as data members. Mobile can be sold, if
stock is available, otherwise purchase will be made. Write a C++ program to
perform following functions :
i. To
accept and display mobile details
ii. To
sale a Mobile (Sale contains Model_Number & Quantity of mobile)
iii. To Purchase a Mobile (Purchase
contains Model_Numbet & Quantity of mobile) */
#include<iostream.h>
#include<conio.h>
#include<string.h>
class inventory
{
int
mno;char mname[30];
int
stock;float price;
public
:
void
accept()
{
cout<<"\n
Enter model no :";
cin>>mno;
cout<<"\n
Enter model name : ";
cin>>mname;
cout<<"\n
enter price : ";
cin>>price;
cout<<"\n
Enter stock : ";
cin>>stock;
}
void
display()
{
cout<<"\n
model no is : "<<mno<<"\n model name :
"<<mname<<"\n price : "<<price<<"\n
stock :"<<stock;
}
int
sale(int no,int q)
{
if(mno==no)
{
if(stock>=q)
{
stock
=stock-q;
cout<<"\n
sale is done : ";
display();
return
2;
}
else
cout<<"\n
purchse is requried .";
//purchase();
return
1;
}
return
0;
}
void
purchase(int no,int q)
{
if(no==mno)
{
stock=stock+q;
cout<<"\n
purchase is done...";
display();
}
}
};
void main()
{
inventory
in[10] ;
int
qt,ans,no;
clrscr();
cout<<"\n
Enter no of models : ";
int
n;
cin>>n;
for(int
i=0;i<n;i++)
in[i].accept();
cout<<"===================================";
for(i=0;i<n;i++)
in[i].display();
cout<<"\n
Enter model to be purchaes and quantity : ";
cin>>no;
cin>>qt;
for(i=0;i<n;i++)
{ ans= in[i].sale(no,qt)
;
}
if(ans==1)
{
cout<<"\n
Enter model to be purchaes and quantity : ";
cin>>no;
cin>>qt;
for(i=0;i<n;i++)
{ in[i].purchase(no,qt);
}
}
getch();
}
slip 29
Reviewed by Dinesh Varal
on
January 31, 2018
Rating:
No comments: