Question

public: bool older(wine &); returns false otherwise int ageDifference(wine &); Postcondition: returns the difference in years
Given the wine class interface below, a) Implement all five member functions. b) write a main() function that tests all membe
public: bool older(wine &); returns false otherwise int ageDifference(wine &); Postcondition: returns the difference in years produced (must be a positive value) between the calling object and the one explicitly passed to the function bool costlier(wine &); // Postcondition: returns true if the calling objectis"costlier than the object explicitly passed to the function returns false otherwise void inputValuesForwineobj); / Prompts the user to enter type, year, and cost of the calling wine object (a bottle) // Postcondition: data members of the calling object are properly loaded with values entered by the user void displaywineobj): / Postcondition: displays the contents of the calling object in a format shown is the sample output private: string type; IIred or white int year double cost; / per bottle retail // year produced xx Get info for bottle-1 Enter wine type, year produced, and coot: Red 2012 79.99 Enter wine type, year produced, and cost: White 2018 25.5 Bottle #1 Type: Red Year: 2012 cost: $79.99 Bottle #2: Type: White Year: 2018 cost: $25.50 Bottle #1 is older ! The age difference between bottle #1 and bottle-2-6 Bottle #1 is more expensive, Press any key to continue..I IIT
Given the wine class interface below, a) Implement all five member functions. b) write a main() function that tests all member function directly or indirectly. Your program output should be similar to the sample output shown below. class wine 2. 5*6-30% 15%
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
#include<cstring>
#include<iomanip>
#include<cmath>
using namespace std;
class wine
{
public:
bool older(wine &);
int ageDifference(wine &);
bool costlier(wine &);
void inputValuesForWineObj();
void displayWineObj();
private:
string type;
int year;
double cost;
};
void wine::inputValuesForWineObj()
{
cout<<"Enter wine type, year produced, and cost: ";
cin>>type>>year>>cost;
}
void wine::displayWineObj()
{
cout<<"\tType: "<<type<<endl;
cout<<"\tYear: "<<year<<endl;
cout<<"\tCost: $"<<setiosflags(ios::fixed)<<setprecision(2)<<cost<<endl;
}
bool wine::older(wine &obj)
{
if(year<obj.year)
return true;
return false;
}
int wine::ageDifference(wine &obj)
{
return abs(year-obj.year);
}
bool wine::costlier(wine &obj)
{
if(cost>obj.cost)
return true;
return false;
}
int main()
{
wine obj1,obj2; //declare wine objects
cout<<"*** Get info for bottle-1 ***"<<endl;
obj1.inputValuesForWineObj();
cout<<"\n*** Get info for bottle-2 ***"<<endl;
obj2.inputValuesForWineObj();
cout<<"\nBottle #1:"<<endl;
obj1.displayWineObj();
cout<<"\nBottle #2:"<<endl;
obj2.displayWineObj();
if(obj1.older(obj2)==true)
cout<<"\nBottle #1 is older!"<<endl;
else
cout<<"\nBottle #2 is older!"<<endl;
cout<<"\nThe age difference between bottle #1 and bottle #2 = "<<obj1.ageDifference(obj2)<<endl;
if(obj1.costlier(obj2)==true)
cout<<"\nBottle #1 is more expensive!"<<endl;
else
cout<<"\nBottle #2 is more expensive!"<<endl;
return 0;
}
Output

koushikhp@koushikhpnew: hp 59书令4)) 9:27 PM Ikoushikho koushikhp@koushikhpnew: g++ winedetails.cpp koushikhp@koushikhpnew:-$ /

Add a comment
Know the answer?
Add Answer to:
Public: bool older(wine &); returns false otherwise int ageDifference(wine &); Postcondition: ret...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Given the following date class interface: class date {private: int month;//1 - 12 int day;//1 -...

    Given the following date class interface: class date {private: int month;//1 - 12 int day;//1 - 28. 29. 30. 31 depending on month & year int year;//4-digit, e.g.. 2017 public: date();//Default constructor (investigate; find what it is used for)//Postcondition: the newly declared date object is initialized to 01/01/2000 date(int mm, int dd, int yyyy);//Second constructor//Postcondition: the newly declared data object is initialized to mm/dd/yyyy void setDate(int mm. int dd. int yyyy);//Postcondition: set the contents of the calling date object to...

  • This project is divided into 3 parts: Part 1. Create a new project and download the arrayList and...

    This project is divided into 3 parts: Part 1. Create a new project and download the arrayList and unorderedArrayList templates that are attached. Create a header file for your unorderedSet template and add it to the project. An implementation file will not be needed since the the new class will be a template. Override the definitions of insertAt, insertEnd, and replaceAt in the unorderedSet template definition. Implement the template member functions so that all they do is verify that the...

  • 1. Here are codes to define a stack class based on dynamic array, please complete the...

    1. Here are codes to define a stack class based on dynamic array, please complete the copy constructor //--- Definition of Stack copy constructor Stack::Stack(const Stack & original) : myCapacity(original.myCapacity), myTop(original.myTop) { //--- Get new array for copy myArray = new(nothrow) StackElement[myCapacity]; if (myArray != 0) // check if memory available                         // copy original's array member into this new array {              // Please complete the function here        } else {          cerr << "*Inadequate memory to allocate...

  • Objectives You will implement and test a class called MyString. Each MyString object keeps track ...

    Objectives You will implement and test a class called MyString. Each MyString object keeps track of a sequence of characters, similar to the standard C++ string class but with fewer operations. The objectives of this programming assignment are as follows. Ensure that you can write a class that uses dynamic memory to store a sequence whose length is unspecified. (Keep in mind that if you were actually writing a program that needs a string, you would use the C++ standard...

  • Q1. Write a recursive function in C++ void printNumberedChars(string str, int i=0) { ... } which...

    Q1. Write a recursive function in C++ void printNumberedChars(string str, int i=0) { ... } which prints each character of the given string str on a new line, with each line numbered 1, 2, 3, …. For example calling the function with printNumberedChars("hello"); should output the following: 1. h 2. e 3. l 4. l 5. o Q2. Write a recursive function in C++ int sumArray(const int* arr, unsigned int size) { ... } which takes an array of integers,...

  • Write a program in C++ that simulates a soft drink machine. The program will need several...

    Write a program in C++ that simulates a soft drink machine. The program will need several classes: DrinkItem, DrinkMachine and Receipt. For each of the classes you must create the constructors and member functions required below. You can, optionally, add additional private member functions that can be used for doing implementation work within the class. DrinkItem class The DrinkItem class will contains the following private data members: name: Drink name (type of drink – read in from a file). Type...

  • Introduction Extend the inheritance hierarchy from the previous project by changing the classes to template classes....

    Introduction Extend the inheritance hierarchy from the previous project by changing the classes to template classes. Do not worry about rounding in classes that are instantiated as integer classes, you may just use the default rounding. You will add an additional data member, method, and bank account type that inherits SavingsAc-count ("CD", or certicate of deposit). Deliverables A driver program (driver.cpp) An implementation of Account class (account.h) An implementation of SavingsAccount (savingsaccount.h) An implementation of CheckingAccount (checkingaccount.h) An implementation of...

  • C++ 1st) [Note: This assignment is adapted from programming project #7 in Savitch, Chapter 10, p.616.]...

    C++ 1st) [Note: This assignment is adapted from programming project #7 in Savitch, Chapter 10, p.616.] Write a rational number class. Recall that a rational number is a ratio-nal number, composed of two integers with division indicated. The division is not carried out, it is only indicated, as in 1/2, 2/3, 15/32. You should represent rational numbers using two int values, numerator and denominator. A principle of abstract data type construction is that constructors must be present to create objects...

  • I've posted 3 classes after the instruction that were given at start You will implement and...

    I've posted 3 classes after the instruction that were given at start You will implement and test a PriorityQueue class, where the items of the priority queue are stored on a linked list. The material from Ch1 ~ 8 of the textbook can help you tremendously. You can get a lot of good information about implementing this assignment from chapter 8. There are couple notes about this assignment. 1. Using structure Node with a pointer point to Node structure to...

  • C++ CODE /* This is program project 2 on page 695. * Before you begin the...

    C++ CODE /* This is program project 2 on page 695. * Before you begin the project, please read the project description * on page 695 first. * * Author: Your Name * Version: Dates */ #include <iostream> #include <cmath> #include <cassert> using namespace std; class Fraction { public: // constructor Fraction(int a, int b); // generate a fraction which is a/b Fraction(int a); // generate a fraction which is a/1 Fraction(); // generate a fraction which is 0/1. i.e...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT