Sie sind auf Seite 1von 12

ASSIGNMENT - 1

OBJECT AND CLASSES


MUDIT ROHILLA
12-H
________________________________________________________________________________
//Q_1
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class book
{
int book_no;
char book_title [20];
float price;
float total_cost(int n)
{
return n*price:
}
public:
void input();
void purchase();
};

void book::input()
{
cout<<"enter book no= ";
cin>>book_no;
cout<<"enter book title = ";
gets(book_title);
cout<<"enter price of book = ";
cin>>price;
}

void book::purchase()
{
int n,y;
cout<<"enter number of books= ";
cin>>n;
y=total_cost(n);
cout<<"total cost of books= "<<y;
}

void main()
{
clrscr();
book b;
b.input;
b.purchase;
}
/* output----------------
enter book no= 567
enter book title = jungle book
enter price of book = 199
enter number of books= 5
total cost of books= 995
*/
//Q_2
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class item
{
int code;
char iname [20];
float price;
int qty;
float offer ;
void getoffer ();
public:
void getstock();
void showitem();
};

void item::getoffer()
{
if(qty<+50)
offer=0;
else if (qty>50 && qty<=100)
offer=float(5)/100*price;
else if (qty>100)
offer=float(10)/100*price;
}

void item::getstock()
{
cout<<" enter code of product= ";
cin>>code;
cout<<"\n enter price= ";
cin>>price;
cout<<"\n enter quantity = ";
cin>>qty;
cout<<"\n enter name of item= ";
gets(iname);
getoffer ();
}

void item::showitem()
{
cout<<"------------------------\nname= "<<iname<<endl<<"price= "<<price<<endl<<"quantity=
"<<qty<<endl<<"offer= "<<offer;
}

void main()
{
clrscr();
item i;
i.getstock();
i.showitem();
getch();
}
/*output-------------------------
enter code of product= 246

enter price= 149

enter quantity = 75

enter name of item= dettol


------------------------
name= dettol
price= 149
quantity= 75
offer= 7.45

*/
//Q_3
#include <iostream.h>
#include <conio.h>
#include <string.h>
#include <stdio.h>

class supply
{
int code;
char foodn[20],sticker[10],foodt[10];
void gettype();
public:
void foodin();
void foodout();
};

void supply :: gettype()


{
if (strcmpi(sticker,"Green")==0)
strcpy(foodt,"Vegetarian");
else if (strcmpi(sticker,"yellow")==0)
strcpy(foodt,"Contain Egg");
else if (strcmpi(sticker,"Red")==0)
strcpy(foodt,"Non-Vegetarian");
}
void supply :: foodin()
{
cout<<" Code = ";
cin>>code;
cout<<" \nFood Name = ";
gets(foodn);
cout<<" \nSticker = ";
gets(sticker);
gettype();
}

void supply :: foodout()


{
cout<<"\nCode = "<<code;
cout<<"\nFood Name = "<<foodn;
cout<<"\nSticker = "<<sticker;
cout<<"\nFood Type = "<<foodt;
}

void main()
{
clrscr();
supply s;
s.foodin();
s.foodout();
getch();
}
/*output-----------------

Code = 12

Food Name = momos

Sticker = green

Code = 12
Food Name = momos
Sticker = green
Food Type = Vegetarian */
//Q_4
#include<iostream.h>
#include<conio.h>
#include<stdio.h>

class resort
{
int rno;
char name[30];
int charges;
int days;
float compute();
public :
void getinfo();
void dispinfo();
};

float resort::compute()
{
float a;
a=days*charges;
if(a>11000)
a=1.02 *days*charges;
return a ;
}

void resort::getinfo()
{
cout<<"enter the room number= ";
cin>>rno;
cout<<"enter the name = ";
gets (name);
cout<<"enter charges per days = ";
cin>>charges;
cout<<"enter days = ";
cin>>days;
}

void resort::dispinfo()
{
cout<<"\n-----------------\n";
cout<<"room number= "<<rno;
cout<<"\nname= "<<name;
cout<<"\ncharges= "<<charges;
cout<<"\ndays= "<<days;
cout<<"\nfinal charges= "<<compute();
}

void main()
{
clrscr();
resort r;
r.getinfo();
r.dispinfo();
getch();
}
/*output-----------
enter the room number= 207
enter the name = mudit
enter charges per days = 1000
enter days = 5
-----------------
room number= 207
name= mudit
charges= 1000
days= 5
final charges= 5000 */

//Q_5
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class bank
{
int accno;
char name[20],acctype;
double balance;
public:
void readdata();
void deposit(int);
void withdraw(int);
void display();
int retaccno();
};

void bank::readdata()
{
cout<<"enter account number= ";
cin>>accno;
cout<<"enter name= ";
gets(name);
cout<<"enter account type s/c= ";
cin>>acctype;
cout<<"enter initial balance= ";
cin>>balance;
}

void bank::deposit(int amt)


{
balance=balance+amt;
}

void bank::withdraw(int amt)


{
if (balance-amt<=1000)
balance=balance-amt;
else
cout<<"insufficient balance ";
}

void bank::display()
{
cout<<"---------------\n";
cout<<"\naccount number= "<<accno;
cout<<"\ndepositor name= "<<name;
cout<<"\naccount type= "<<acctype;
cout<<"\nbalance amnount= "<<balance;
}

int bank::retaccno()
{
return accno;
}

bank B[2];
void main()
{
clrscr();
int choice;
for(int i=0;i<2;i++)
{
B[i].readdata();
}
do
{
cout<<"\npress 1 to deposit the amount";
cout<<"\npress 2 to withdraw amount ";
cout<<"\npress 3 to display the account no. ";
cout<<"\npress 4 to exit";
cin>>choice;
switch(choice)
{
case 1:{
int a,b;
int flag=0;
cout<<"enter account number= ";
cin>>a;
cout<<"enter amount to be deposited= ";
cin>>b;
for(i=0;i<2;i++)
{
if (B[i].retaccno()==a)
{
B[i].deposit(b);
flag=1;break;
}
}
if(flag==0)
{
cout<<"invalid account number";
}break;
}
case 2:{
int a,b;
int flag=0;
cout<<"enter account number= ";
cin>>a;
cout<<"enter amount to be withdraw= ";
cin>>b;
for(i=0;i<2;i++)
{
if (B[i].retaccno()==a)
{
B[i].withdraw(b);
flag=1;break;
}
}
if(flag==0)
{
cout<<"invalid account number";
}break;
}
case 3:{
int a,b;
int flag=0;
cout<<"enter account number= ";
cin>>a;
for(i=0;i<2;i++)
{
if (B[i].retaccno()==a)
{
B[i].display();
flag=1;break;
}
}
if(flag==0)
{
cout<<"invalid account number";
}break;
}
case 4:break;
}
}while(choice!=4);
getch();
}
/*output----------------
enter account number= 1111
enter name= mudit
enter account type s/c= s
enter initial balance= 10000
enter account number= 1112
enter name= devansh
enter account type s/c= c
enter initial balance= 100000

press 1 to deposit the amount


press 2 to withdraw amount
press 3 to display the account no.
press 4 to exit1
enter account number= 1111
enter amount to be deposited= 1000

press 1 to deposit the amount


press 2 to withdraw amount
press 3 to display the account no.
press 4 to exit3
enter account number= 1111
---------------

account number= 1111


depositor name= mudit
account type= s
balance amnount= 11000
press 1 to deposit the amount
press 2 to withdraw amount
press 3 to display the account no.
press 4 to exit4 */
//Q_6
#include<iostream.h>
#include<string.h>
#include<stdio.h>
void inputdata();
void outputdata();
void searchdisplay();
class Donor
{
int donorno;
char donorname[20];
char bloodgroup[4];
public:
void input();
void output();
char*checkgroup()
{
return bloodgroup;
}
};
void Donor::input()
{
cout<<"enter donor no.";
cin>>donorno;
cout<<"enter name";
gets(donorname);
cout<<"enter blood group";
gets(bloodgroup);
}
void Donor::output()
{
cout<<donorno<<endl<<donorname<<endl<<bloodgroup<<endl;
}
Donor d[3];
void main()
{
int choice;
do
{
cout<<endl<<"1 for input"<<endl;
cout<<"2 for display"<<endl;
cout<<"3 for searching"<<endl;
cout<<"4 for exit"<<endl;
cin>>choice;
switch(choice)
{
case 1: inputdata();
break;
case 2: outputdata();
break;
case 3: searchdisplay();
break;
case 4: cout<< PROGRAM TERMINATED!!!”;
break;
}
}while(choice!=4);
}
void inputdata()
{
for(int i=0;i<3;i++)
{
d[i].input();
}
}
void outputdata()
{
for(int i=0;i<3;i++)
{
d[i].output();
}
}
void searchdisplay()
{
char bg[4];
cout<<"enter bloodgrp";
gets(bg);
for(int i=0;i<3;i++)
{
if(strcmp(d[i].checkgroup(),bg)==0)
{
d[i].output();
}
}
}
/*output----------------------------
1 for input
2 for display
3 for searching
4 for exit
1
enter donor no.1
enter name bjjbcs
enter blood group a+
enter donor no.2
enter name snj
enter blood group b+
enter donor no.3
enter name kjsbnju
enter blood group o+
1 for input
2 for display
3 for searching
4 for exit
2
1
bjjbcs
a+
2
snj
b+
3
kjsbnju
o+
1 for input
2 for display
3 for searching
4 for exit
3
enter bloodgrpo+
3
kjsbnju
o+
1 for input
2 for display
3 for searching
4 for exit
4
PROGRAM TERMINATED!!! */