Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

# 4 – Library Application with Music and Video please use c++ programming langua

ID: 3598362 • Letter: #

Question

# 4 – Library Application with Music and Video

please use c++ programming language.


Due Wednesday, October 25, at the beginning of class. Hand in hard copy of your code and be
prepared to run your program. Develop your program as follows:
• Complete part 1 before you begin part 2.
• The main program and each class definition must be in separate files.
• Hard code test data in the program. Do not enter test data when you run the program.
• Use functions to break your main program into components
• Add a comment at the beginning of all classes and functions to describe behavior.
Part 1 – Publication Class
In your solution to homework 3, rename Book to Publication wherever it appears. Test your
program to ensure it works properly.
Part 2 – Book, Music, and Video classes
Add a new Book class, as well as Music and Video classes. All three classes are derived from the
Publication class. Add these member variables:
Book class:
• pages
• format (hardcover, softcover, digital)
Music class:
• duration (seconds)
• format (MP3, AAV, WAV)
Video class:
• resolution (low, high, 4K)
• producer
All three classes should have constructors, get, and set functions.
Extend your main program to edit and display Publication and Person data, using this menu:
1) Display people
2) Display publications
3) Edit people
4) Edit publications
5) Check out publication
6) Check in publication
7) Quit

Page 2

Challenge (optional - 1 bonus point)
Write a Date class with member variables year, month, and day, and member functions
• Constructor, setDate, and getDate
• overloaded ‘-‘ operator (calculates days between two Date objects)
Add a menu option to enter today’s date, and save the checkout date for each Publication.
Publications may be checked out for 21 days. Extend your main program to determine if a
Publication is overdue and display all overdue Publications.

Explanation / Answer

package com.onetoMany;

import java.util.Set;

public class Customer {

private int customerID;

private String customerName;

private Set items;

public int getCustomerID() {

return customerID;

}

public void setCustomerID(int customerID) {

this.customerID = customerID;

}

public String getCustomerName() {

return customerName;

}

public void setCustomerName(String customerName) {

this.customerName = customerName;

}

public Set getItems() {

return items;

}

public void setItems(Set items) {

this.items = items;

}

}

package com.onetoMany;

import java.util.HashSet;

import java.util.List;

import java.util.Set;

import org.hibernate.SessionFactory;

import org.hibernate.Transaction;

import org.hibernate.classic.Session;

import Pack.util.HibernateUtil;

public class OneToManyDAOImpl implements OneToManyDAO {

@Override

public void saveCustomer() {

Customer c1 = new Customer();

c1.setCustomerID(101);

c1.setCustomerName("A");

Item i1 = new Item();

i1.setItemID(9001);

i1.setItemName("X");

i1.setPrice(5000);

Item i2 = new Item();

i2.setItemID(9002);

i2.setItemName("Y");

i2.setPrice(6000);

Set items = new HashSet();

items.add(i1);

items.add(i2);

c1.setItems(items);

SessionFactory factory = HibernateUtil.getSessionFactory();

Session ses = factory.openSession();

Transaction tx = ses.beginTransaction();

ses.save(c1);

tx.commit();

ses.close();

}

}