Professional Documents
Culture Documents
/*Write a C++ program to copy the value of one object to another object using
copy constructor.*/
#include <iostream>
class Number {
private:
int a ;
public:
Number(){}
Number(int x){
a = x;
cout<<"constructor Called"<<endl;
Number(Number &obj){
a = obj.a;
void Display(){
};
int main() {
Number num1(10);
LAB#3 ROLL NO:DT-45
num1.Display();
num2.Display();
return 0;
2. Create a class tollbooth. The two data items are a type int to hold the total number
of cars and a type double to hold the total amount of money collected. A
constructor initializes both these to 0. When a car passes the toll, a member
function called payingCar( ) increments the car total and adds 0.50 to the cash
total. Another member function displays the two totals. DESIGN and IMPLEMENT
this case. Make assumptions (if required) and include it in the description before
#include <iostream>
class tollbooth
public:
int totalcars;
double totalMoney;
tollbooth()
{
LAB#3 ROLL NO:DT-45
totalcars = 0;
totalMoney = 0;
void paying_car()
totalcars++;
totalMoney += 0.50;
cout << "Number of cars passed: " << totalcars << endl;
};
int main()
tollbooth cars;
cars.paying_car();
cars.paying_car();
cars.paying_car();
cars.paying_car();
cars.displayTotals();
return 0;
LAB#3 ROLL NO:DT-45
/*Some of the characteristics of a book are the title, author(s), publisher, ISBN,
price,
and year of publication. Design a class bookType that defines the book as an
ADT.
Each object of the class bookType can hold the following information about a
book: title, up to four authors, publisher, ISBN, price, and number of copies in
stock. To keep track of the number of authors, add another member variable.
type bookType.
For example, the usual operations that can be performed on the title are to
show the title, set the title, and check whether a title is the same as the actual
title of the book. Similarly, the typical operations that can be performed on the
number of copies in stock are to show the number of copies in stock, set the
number of copies in stock, update the number of copies in stock, and return the
number of copies in stock. Add similar operations for the publisher, ISBN, book
price, and authors. Add the appropriate constructors and a destructor (if one is
needed).
Write a program that uses the class bookType and tests various operations on
the objects of the class bookType. Declare an array of 100 components of type
bookType. Some of the operations that you should perform are to search for a
book by its title, search by ISBN, and update the number of copies of a book.*/
#include <iostream>
#include <string>
class booktype
public:
string actualTitle;
string title2;
string publisher;
string ISBN;
double price;
int numofcopies;
int numofauthors;
string authors[4];
booktype()
actualTitle = "";
title2 = "";
publisher = "";
ISBN = "";
price = 0.0;
numofcopies = 0;
numofauthors = 0;
authors[i] = "";
}
LAB#3 ROLL NO:DT-45
void set_title()
cout << "Enter a Title for the book: " << endl;
void display_title()
cout << "The title set for the book is: " << title2 << endl;
void checkTitle()
if (title2 == actualTitle)
cout << "The Actual title and the set title are the same" << endl;
else
cout << "The Actual Title and Set title are different" << endl;
}
LAB#3 ROLL NO:DT-45
void set_copies()
void display_copies()
cout << "The number of copies is: " << numofcopies << endl;
void set_publisher()
void display_publisher()
cout << "The name of the publisher is: " << publisher << endl;
void set_ISBN()
cin>> ISBN;
void display_ISBN()
cout << "ISBN number of the book is: " << ISBN << endl;
void set_authors()
if (numofauthors <= 4)
cout << "Enter the name of author " << i + 1 << ": ";
void display_authors()
LAB#3 ROLL NO:DT-45
cout << "The Name/s of the author/s are: " << endl;
void set_price()
void display_price()
cout << "The Price of the book is: " << price << endl;
numofcopies = newCopies;
};
int main()
booktype books[100];
books[0].set_title();
books[0].display_title();
books[0].set_authors();
books[0].display_authors();
books[0].set_copies();
books[0].
display_copies();
books[0].set_publisher();
books[0].display_publisher();
books[0].set_ISBN();
LAB#3 ROLL NO:DT-45
books[0].display_ISBN();
books[0].set_price();
books[0].display_price();
// Search by title
string searchTitle;
if (books[0].searchByTitle(searchTitle))
else
// Search by ISBN
string searchISBN;
if (books[0].searchByISBN(searchISBN))
LAB#3 ROLL NO:DT-45
else
int newCopies;
books[0].updateCopies(newCopies);
books[0].display_copies();
return 0;