/* Filename: product2.cpp Author: Br. David Carlson Date: July 5, 1998 Revised: July 17, 2000 This file implements the Product class that was set up in product2.h. */ #include "product2.h" /* Given: InitialName A string containing the product name. InitialYear The year this product was made. InitialPrice The product's price. Task: This is the default constructor. It creates a new Product object containing the 3 items listed above. Return: Nothing is directly returned, but the object is created. */ Product::Product(ShortString InitialName, int InitialYear, float InitialPrice) { // Recall that you cannot simply assign one string into another. strcpy(Name, InitialName); Year = InitialYear; Price = InitialPrice; } /* Given: Nothing (other than the implicit object). Task: To print the data contained in this object. Return: Nothing. */ void Product::Print(void) const { cout << "Product name: " << Name << endl << "Year made: " << Year << endl << "Price: " << Price << endl << endl; } /* Given: NewPrice A new price to use for the implicit Product object. Task: To change the price of this object to NewPrice. Return: Nothing directly, but the Product object is modified. */ void Product::ChangePrice(float NewPrice) { Price = NewPrice; } /* Given: Nothing. Task: To look up the name of the implicit Product object. Return: ProductName The name of this Product object. */ void Product::GetName(ShortString ProductName) const { // Once again, you cannot use assignment with strings. strcpy(ProductName, Name); } /* Given: Nothing. Task: To look up the year the implicit Product object was made. Return: This year in the function name. */ int Product::GetYear(void) const { return Year; } /* Given: Nothing. Task: To look up the price of the implicit Product object. Return: The price of this Product object, in the function name. */ float Product::GetPrice(void) const { return Price; }