1 / 10

Lecture 1 & 2 – Case Study

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 of the stock of the books. The system should be able to:

yasuo
Download Presentation

Lecture 1 & 2 – Case Study

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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, 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. • Design the UML class diagrams for this system. • Write the C++ program for this system.

  3. Author Book Case Study– Design of Class Diagrams -title: string -author: Author -price: double -qtyInStock:int = 0 -name: string -email:string -gender:char -books:Book[*] 1 1..n +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, char gender) +setEmail(email:string):void +getName():string +getEmail():string +getGender():string +print():void

  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; intqtyInStock; public: Book(string name, Author author, double price, intqtyInStock): name(name), author(author), price(price), qtyInStock(qtyInStock){ } void setPrice(double price); void setQtyInStock(intqtyInStock); string getName(); Author getAuthor(); double getPrice(); intgetQtyInStock(); void print(); };

  6. Case Study– Class Implementations void Book::setPrice(double price) { this->price = price; } void Book::setQtyInStock(intqtyInStock) { this->qtyInStock = qtyInStock; } string Book::getName() { return name; } double Book::getPrice() { return price; } int Book::getQtyInStock() { return qtyInStock; } Author Book::getAuthor() { return author; } void Book::print() { cout << "\nTitle\t: " << name << 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<Book> 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 (inti=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?

More Related