Professional Documents
Culture Documents
BATCH: B7
ENROLL: 19103229
Q1.
#include<iostream>
#include <string>
class Invoice
public:
string getPartNumber();
void setPartDescription(string);
string getPartDescription();
void setItemQuantity(int);
int getItemQuantity();
void setItemPrice(int);
int getItemPrice();
int getInvoiceAmount();
private:
string partNumber;
string partDescription;
int itemQuantity;
int itemPrice;
};
partNumber=number;
partDescription=description;
if(quantity>0)
itemQuantity=quantity;
else
itemQuantity=0;
if(price>0)
itemPrice=price;
else{
itemPrice=0;
if ( number.length() <= 25 )
partNumber = number;
if ( number.length() > 25 ){
partNumber = number.substr( 0, 25 );
cout << "Name \"" << number <<"\" exceeds maximum length (25).\n"<< "Limiting partNumber to
first 25 characters.\n" << endl;
if ( description.length() <= 25 )
partDescription = description;
if ( description.length() > 25 ){
partDescription = description.substr( 0, 25 );
cout << "Name \"" << description <<"\" exceeds maximum length (25).\n"<< "Limiting
partDescription to first 25 characters.\n" << endl;
if(quantity>0)
itemQuantity=quantity;
else{
itemQuantity=0;
}
void Invoice::setItemPrice(int price )
if(price>0)
itemPrice=price;
else{
itemPrice=0;
string Invoice::getPartNumber(){
return partNumber;
string Invoice::getPartDescription(){
return partDescription;
int Invoice::getItemQuantity(){
return itemQuantity;
int Invoice::getItemPrice(){
return itemPrice;
int Invoice::getInvoiceAmount(){
return itemQuantity*itemPrice;
int main(){
Invoice Invoice1("ed34","HP Laptop",1,64999);
cout << "Invoice1's initial part number is: "<< Invoice1.getPartNumber()<< "\nItem description is: "<<
Invoice1.getPartDescription()<<endl;
cout<< "Quantity per item is: "<< Invoice1.getItemQuantity()<< "\nPrice per item is: "<<
Invoice1.getItemPrice()<< endl;
cout << "Invoice2's initial part number is: "<< Invoice2.getPartNumber()<< "\nItem description is: "<<
Invoice2.getPartDescription()<<endl;
cout<< "Quantity per item is: "<< Invoice2.getItemQuantity()<< "\nPrice per item is: "<<
Invoice2.getItemPrice()<< endl;
Q2.
#include <bits/stdc++.h>
class Product {
private:
int price;
public:
Product(string id, int price, string name, string date) : id(id), price(price), name(name),
date(date){};
};
};
private:
string expiry;
public:
Consumable(string id, int price, string name, string date, string expiry) : Product(id, price,
name, date), expiry(expiry){};
};
public:
NonConsumable(string id, int price, string name, string date) : Product(id, price, name,
date){};
};
class Customer {
private:
int id;
public:
Customer(string name, string address, int Id) : name(name), address(address), id(Id) {};
return false;
};
private:
public:
bool isMember() {
return true; }
};
int Member::ID = 0;
public:
NonMember(string name, string address, int phNo) : Customer(name, address, phNo) {};
bool isMember() {
return false;
};
class Store {
public:
public:
Store(){};
void insertProduct(string id, int price, string name, string date, bool consumable, string
expiry = "") {
if(consumable) {
} else {
if(isMember) {
double total = 0;
if (isMember) {
for(auto y: products) {
if(y->getId() == x) {
total += y->getPrice();
break;
totalDiscount += .2 * total;
} else {
double discount = 0;
for(auto y: products) {
if(y->getId() == x) {
if(y->isConsumable()) {
} else {
total += y->getPrice();
totalDiscount += discount;
total -= discount;
return total;
double getMaxDiscount() {
return maxDiscount; }
double getTotalDiscount() {
return totalDiscount;
};
int main() {
Store s;
if(i < 5) {
} else {
i * 10 + i);
for(auto x: s.customers) {
cout << x->getId() << " " << x->isMember() << " " << s.getBill(x->getId(),
x->isMember(), prodId) << '\n';
}
Q3. class ABC
int x;
public:
ABC() { cout<<”1”; }
~ABC() { cout<<”2”; }
};
class KLM
int y;
public:
~KLM() { cout<<”4”; }
};
class XYZ
ABC O6;
public:
~XYZ() { cout<<”6”; }
};
int main() { XYZ *O7; KLM *O8; O7 = new XYZ; O8 = new KLM; delete(O7); return 0; }
🡺 131151311316242
Q4.
class A
public:
A(){cout<<"1";}
A(int x){cout<<"2";}
};
class B
A O1;
public:
B(){cout<<"3";}
B(int x){cout<<"4";}
B(int x, int y):O1(5) {cout<<"5";}
};
class C : public B
public:
C(){cout<<"6";}
C(int x){cout<<"7";}
};
🡺 131425
Q5.
class A
public:
A() { cout<<”1”; }
~A() { cout<<”2”; }
};
class B
A *O1;
public:
~B() {delete(O1);}
};
class C
A O2;
public:
C() { cout<<”5”; }
~C() { cout<<”6”; }
};
class D
A *O3;
public:
};
int main() { A *O4 = new A; B O5; C *O6, *O7 = new C; D *O8 = new D(O4); delete(O8);
delete(O7); return
0;}
🡺 11156622
Q6.
class A
public:
A(){cout<<"1";}
};
public:
};
class C : public B
public:
C(){cout<<" 3";}
};
class D : public C
public:
D(){cout<<"4";}
};
class E
public:
E(){cout<<" 5";}
};
class F : public E
public:
F(){cout<<"6";}
};
public:
};
class H : public G
public:
H(){cout<<" 8";}
};
class I : public H
public:
I(){cout<<"9";}
};
{
public:
J(){cout<<" 10";}
};
🡺 15623478910