Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 1 & 2 – Case Study TCP1201: 2013/2014. Case Study – Book Store System You are assigned to create a simple system for a bookstore that keeps track.

Similar presentations


Presentation on theme: "Lecture 1 & 2 – Case Study TCP1201: 2013/2014. Case Study – Book Store System You are assigned to create a simple system for a bookstore that keeps track."— Presentation transcript:

1 Lecture 1 & 2 – Case Study TCP1201: 2013/2014

2 Case Study – Book Store System You are assigned to create a simple system for a bookstore that keeps track of the stock of the books. The system should be able to:  Store the following details; title, author (assume only one author for each book), price and number-in-stock for a particular book title.  Store the following details; name, email, gender for a particular author.  Allow the details of the books and authors to be retrieved. a) Design the UML class diagrams for this system. b) Write the C++ program for this system.

3 Case Study– Design of Class Diagrams Book -title: string -author: Author -price: double -qtyInStock:int = 0 +Book(name:string, author:Author, price:double, qtyInStock:int) +getName(): string +getAuthor():Author +getPrice():double +setPrice(price:double):void +getQtyInStock():int +setQtyInStock(qtyInStock:int):void +print():void Author -name: string -email:string -gender:char +Author(name:string, email:string, char gender) +setEmail(email:string):void +getName():string +getEmail():string +getGender():string +print():void 1 1

4 Case Study– Class Interfaces class Author { string name; string email; char gender; public: Author(string name, string email, char gender) : name(name), email(email), gender(gender) {} void setEmail(string email); string getName(); string getEmail(); char getGender(); void print(); };

5 Case Study– Class Interfaces class Book { string title; Author author; double price; int qtyInStock; public: Book(string title, Author author, double price, int qtyInStock): title(title), author(author), price(price), qtyInStock(qtyInStock) { } void setPrice(double price); void setQtyInStock(int qtyInStock); string getTitle(); Author getAuthor(); double getPrice(); int getQtyInStock(); void print(); };

6 Case Study– Class Implementations void Book::setPrice(double price) { this->price = price; } void Book::setQtyInStock(int qtyInStock) { this->qtyInStock = qtyInStock; } string Book::getTitle() { return title; } double Book::getPrice() { return price; } int Book::getQtyInStock() { return qtyInStock; } Author Book::getAuthor() { return author; } void Book::print() { cout << "\nTitle\t: " << title << endl; cout << "Author\t: " << author.getName() << endl; cout << "Price\t: " << price << endl; cout << "Quantity: " << qtyInStock << endl; }

7 Case Study– Class Implementations void Author::setEmail(string email) { this->email = email; } string Author::getName() { return name; } string Author::getEmail() { return email; } void Author::print() { cout << "\n\nAuthor Details:" << endl << endl; cout << "Name: " << name << endl; cout << "Email: " << email << endl; }

8 Case Study – Using the classes (Driver) int main() { vector books; Author author1("Jane Austen","ja@gmail.com",'F'); books.push_back(Book("Pride and Prejudice", author1, 39, 2)); books.push_back(Book("Sense and Sensibility", author1, 30, 3)); books.push_back(Book("Emma", author1, 50, 1)); Author author2("Charles Dickens","ja@gmail.com",'M'); books.push_back(Book("Oliver Twist", author2, 25, 1)); books.push_back(Book("A Chirstmas Carol", author2, 35, 5)); for (int i=0; i<books.size(); i++) books[i].print(); }

9 Case Study – Output

10 Case Study – Creating a Bookstore  Now, how do we use the Book and Author classes to create a more complete Bookstore system?  What are the functions needed for a Bookstore system? Add and delete books Search for books by Title Search for books by Author Change the price for a book Change the quantity in stock for a book Can you create a Bookstore system now using the Book and Author classes?


Download ppt "Lecture 1 & 2 – Case Study TCP1201: 2013/2014. Case Study – Book Store System You are assigned to create a simple system for a bookstore that keeps track."

Similar presentations


Ads by Google