
#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

Public: bool older(wine &); returns false otherwise int ageDifference(wine &); Postcondition: ret...
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 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 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 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 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 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. 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.] 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 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 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...