100 likes | 268 Views
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:
E N D
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: • 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.
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
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(); };
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(); };
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; }
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; }
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(); }
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?