Question

In: Computer Science

This is my last assignment in a programming class I had to take as a prerequisite...

This is my last assignment in a programming class I had to take as a prerequisite for a database course (seems odd). The instructor has been awful and I haven't learned much of anything. I use VBA at work and just can't follow C++. I'm stuck on this assignment and have no idea what I'm doing. I'm a database guy at work, I'm not a programmer. Please help.

In C++, a program that performs the following tasks:

1.      Design a Book class that has three data members:

string title

int   pages

double price

2.      Add constructors and methods (as well as method parameters when necessary):

Book()         // constructor(s)

getBookInfo()   // print title, pages, price

setPrice()     // change price

3.      In the main() function, create two Book objects:

b1("C++ Programming", 834, 93.53)

b2("Data Structures", 217, 64.42)

4.      Change the price of b2 to 55.46 using the setPrice() method.

5.     Using cout, Print out book information using the getBookInfo() method as shown below:

C++ Programming 834 93.53

Data Structures 217 55.46

IN C++, a program that performs the following tasks:

1.      Derive a TextBook class (child) from the Book class (parent).

2.      Add new data members:

string school

double discount

3.      Add new constructors and methods (as well as method parameters when necessary):

TextBook()           // constructor(s)

compTextBookPrice()  // price = price - discount

4.      Override inherited methods:

getBookInfo()        // print title, pages, price, school, discount

5.      In the main() function, create two Book objects and two TextBook objects:

b1("C++ Programming", 834, 93.53)

b2("Data Structures", 217, 64.42)

tb1("Database", 365, 74.41, "YSU", 20.00)

tb2("Networks", 522, 92.58, "YSU", 20.00)

6.      Using cout, print out book information as shown below:

C++ Programming  834  93.53

Data Structures  217  64.42

Database         365  54.41 YSU 20.00

Networks         522  72.58 YSU 20.00

Solutions

Expert Solution

check out the solution and do comment for any queries.

--------------------------------------------------------

#include <iostream>

using namespace std;

class Book
{
private:
string title;
int pages;
double price;
public:
// default constructor - initialize with default values
Book()
{
title = " ";
pages = 0;
price = 0.0;
}
// parameterized constructor - initialized with given values
Book(string t, int pg, double p)
{
title = t;
pages = pg;
price = p;
}
// print title , pages, price
void getBookInfo()
{
cout << "\n" << title << "\t" << pages << "\t" << price;
}
// pass the value of changed price
void setPrice(double p)
{
price = p;
}
};


int main() {
// 2 book objects
Book b1("C++ Programming", 834, 93.53);
Book b2("Data Structures", 217, 64.42);
// change the price of b2
b2.setPrice(55.46);
// print the information
b1.getBookInfo();
b2.getBookInfo();
}

-----------------------------------

code :

----------

Output ::

----------------------------------------------------------

Program extension with Inheritance concept.

-------------

#include <iostream>
#include <iomanip>

using namespace std;

class Book
{
public:
string title;
int pages;
double price;
public:
// default constructor
Book()
{
title = " ";
pages = 0;
price = 0.0;
}
// parameterized constructor
Book(string t, int pg, double p)
{
title = t;
pages = pg;
price = p;
}
// print title , pages, price
void getBookInfo()
{
cout << "\n" << title << "\t" << pages << "\t" << price;
}
// pass the value of changed price
void setPrice(double p)
{
price = p;
}
};

// child class
class TextBook : public Book
{
public:
// class members
string school;
double discount;
public:
// default constructor
TextBook() : Book()
{
school = " ";
discount = 0.0;
}
// parameterized constructor - call the super class constructor as shown below passing required parameters to initialize
TextBook(string t, int pg, double p, string s, double d) : Book(t, pg, p)
{
school = s;
discount = d;
}
// computes the price after deducting discount
void compTextBookPrice()
{
price = price - discount;
}
// override inherit methods
void getBookInfo()
{
cout << "\n" << title << "\t" << pages << "\t" << price << "\t" << school << "\t" << discount;
}
};

int main() {
// 2 book objects
Book b1("C++ Programming", 834, 93.53);
Book b2("Data Structures", 217, 64.42);
// 2 textbook objects
TextBook tb1("Database", 365, 74.41, "YSU", 20.00);
TextBook tb2("Networks", 522, 92.58, "YSU", 20.00);
  
// print the information
b1.getBookInfo();
b2.getBookInfo();
  
cout << fixed << showpoint << setprecision(2); // to print 2 digits after decimal point
// compute the price after discount by a function call
tb1.compTextBookPrice();
tb2.compTextBookPrice();
// print information of textbook
tb1.getBookInfo();
tb2.getBookInfo();
}

-----------------------

code :

-------------------------------------------------

OUTPUT ::


Related Solutions

Hello i am working on an assignment for my programming course in JAVA. The following is...
Hello i am working on an assignment for my programming course in JAVA. The following is the assignment: In main, first ask the user for their name, and read the name into a String variable. Then, using their name, ask for a temperature in farenheit, and read that value in. Calculate and print the equivalent celsius, with output something like Bob, your 32 degrees farenheit would be 0 degrees celsius Look up the celsius to farenheit conversion if you do...
I entered in this code for my programming fundamentals class for this question To encourage good...
I entered in this code for my programming fundamentals class for this question To encourage good grades, Hermosa High School has decided to award each student a bookstore credit that is 10 times the student’s grade point average. In other words, a student with a 3.2 grade point average receives a $32.0 credit. Create an application that prompts a student for a name and grade point average, and then passes the values to a method (computeDiscount) that displays a descriptive...
I have the following code for my java class assignment but i am having an issue...
I have the following code for my java class assignment but i am having an issue with this error i keep getting. On the following lines: return new Circle(color, radius); return new Rectangle(color, length, width); I am getting the following error for each line: "non-static variable this cannot be referenced from a static context" Here is the code I have: /* * ShapeDemo - simple inheritance hierarchy and dynamic binding. * * The Shape class must be compiled before the...
I am struggling with this assignment for my java class. Objectives: Your program will be graded...
I am struggling with this assignment for my java class. Objectives: Your program will be graded according to the rubric below. Please review each objective before submitting your work so you don’t lose points. 1.Create a new project and class in Eclipse and add the main method. (5 points) 2. Construct a Scanner to read input from the keyboard. (5 points) 3. Prompt the user with three questions from the Psychology Today quiz, and use the Scanner to read their...
Last semester, the students in my Finite Math class had an average quiz score of 83...
Last semester, the students in my Finite Math class had an average quiz score of 83 with a standard deviation of 2. Assume that the scores are approximated by a normal distribution. a) What percent of students scored higher than an 86 on the quiz? b) What percent of students scored less than a 79 on the quiz? c) What percent of students scored between a 79 and an 86? d) What happens when you try to find the percent...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class,...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class, you are to have the following data members: name: String (5 pts) id: String   (5 pts) hours: int   (5 pts) rate: double (5 pts) private members (5 pts) You are to create no-arg and parameterized constructors and the appropriate setters(accessors) and getters (mutators). (20 pts) The class definition should also handle the following exceptions: An employee name should not be empty, otherwise an exception...
So previously in my class I had to write a python program where the user would...
So previously in my class I had to write a python program where the user would enter the price for 5 different items, and it would calculate the subtotal, total tax owed and the total amount owed. Now I need to write a program that would do the same but would be done using modules in the code, I am having a hard time figuring modules out. Below is the code from the original program not using modules: # Enter...
For My Programming Lab - Java: Write a Temperature class that will hold a temperature in...
For My Programming Lab - Java: Write a Temperature class that will hold a temperature in Fahrenheit and provide methods to get the temperature in Fahrenheit, Celsius, and Kelvin. The class should have the following field: • ftemp: a double that holds a Fahrenheit temperature. The class should have the following methods : • Constructor : The constructor accepts a Fahrenheit temperature (as a double ) and stores it in the ftemp field. • setFahrenheit: The set Fahrenheit method accepts...
................................................ ................................................ This programming lab assignment requires that you create a class and use an equals...
................................................ ................................................ This programming lab assignment requires that you create a class and use an equals method to compare two or more objects. Your should use your QC5 as a reference. …………………………...…….. …………………………...……. Instructions LAB5 Instructions Using QC5 as a model, create a Rectangle class and a CompareUsingequalsMethod class that uses an   equals Method to determine if two rectangles are equal if and only if their areas are equal. The Rectangle class should have two instance variables length and width....
I am doing a paper on stressors and my stressor is my job. I have had...
I am doing a paper on stressors and my stressor is my job. I have had an arguement with a superior who is know for being a bully, but i stood up to him and could end up unemployed. Having four kids, a wife, and bills to pay, this could be devastating. Using this stressor, what physiological changes occur in the brain due to the stress response? And what emotional and cognitive effects might occur due to this stressful situation?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT