Lab Assignment 3
Lab Assignment 3
Class: BEE-2
QUESTION NO # 01-03:
#include<iostream>
struct sales_data{
string bookno;
unsigned units_sold = 0;
};
return item.bookno;
item1.units_sold += item2.units_sold;
item1.revenue += item2.revenue;
int main(){
sales_data s1;
double price=0;
cout<<"1.Enter Book ISBN Number: "<<endl;
if(cin>>s1.bookno>>s1.units_sold>>price)
{ s1.revenue = s1.units_sold *
price;
sales_data trans;
if(ISBN(s1) == ISBN(trans)){
combine(s1, trans);
else
cout << "Total Book ISBN Number: "<<s1.bookno<<endl << "Total Unit Solds: "
s1=trans;
cout << "Total Book ISBN Number: "<<s1.bookno<<endl << "Total Unit Solds: "
<< s1.units_sold<<endl << "Total Revenue: "
else{
return 0;
OUTPUT
#include <string>
private:
string name;
string addr;
public:
// functions required
// constructors required
Person()=default;
};
return is;
return os;
}
Question no # 05,06 and 07:
#include <iostream>
#include <string>
struct Sales_data {
string bookNo;
unsigned units_sold = 0;
};
units_sold += rhs.units_sold;
revenue += rhs.revenue;
return *this;
if(units_sold != 0)
else
return revenue;
<< item.avg_price();
return os;
double price = 0;
return is;
sum.combine(item2);
return sum;
int main()
Sales_data total;
if(read(cin, total))
Sales_data trans;
cout<<"transaction :"<<endl;
while(read(cin, trans))
if(total.isbn() == trans.isbn())
total.combine(trans);
else
total = trans;
cout<<"Output: \n"<<endl;
else
return 0;
OUTPUT:
Question no # 08:
#include <iostream>
#include <string>
struct Sales_data {
// constructor
Sales_data() = default;
p) :
{} Sales_data(istream &s);
// member
string bookNo;
unsigned units_sold = 0;
const;
};
units_sold += rhs.units_sold;
revenue += rhs.revenue;
return *this;
if(units_sold != 0)
else
return revenue;
<< item.avg_price()<<endl;
return os;
double price = 0;
cout<<"please enter ISBN number, ITEM sold and PRICE of the BOOK."<<endl;
is >> item.bookNo >> item.units_sold >>
price;
return is;
sum.combine(item2);
return sum;
Sales_data::Sales_data(istream& is)
read(is, *this);
int main()
}
OUTPUT:
Question no # 09:
#include <iostream>
#include <string>
// To use read here, we must move read before class definition. But when we
struct Sales_data;
struct Sales_data {
// constructor
Sales_data() = default;
// member
string bookNo;
unsigned units_sold = 0;
};
units_sold += rhs.units_sold;
revenue += rhs.revenue;
return *this;
if(units_sold != 0)
else
return revenue;
}
istream& read(istream &is, Sales_data& item)
double price = 0;
cout<<"please enter ISBN number, ITEM sold and PRICE of the BOOK."<<endl;
return is;
<< item.avg_price()<<endl;
return os;
sum.combine(item2);
return sum;
int main()
return 0;
OUTPUT
QUESTION NO# 10:
#include <iostream>
#include <string>
// To use read here, we must move read before class definition. But when we
struct Sales_data;
struct Sales_data {
public:
// constructor
// member
string bookNo;
unsigned units_sold = 0;
};
Sales_data& Sales_data::combine(const Sales_data& rhs)
units_sold += rhs.units_sold;
revenue += rhs.revenue;
return *this;
if(units_sold != 0)
else
return revenue;
double price = 0;
cout<<"please enter ISBN number, ITEM sold and PRICE of the BOOK."<<endl;
return is;
return os;
sum.combine(item2);
return sum;
int main()
Sales_data total(cin);
if(!total.isbn().empty())
Sales_data trans;
while(read(cin, trans))
if(total.isbn() == trans.isbn())
total.combine(trans);
else
total = trans;
}
else
return 0;
Output: