I'm at the very last bit of this project. I think i am confusing myself at this point. I need to do one last function called showCost. The function is to print the total cost and the average cost. I'm at a loss one how to do this. Wonder if I might get some help. Please take a look and let me know.
//*****************************************************************************
// TITLE: Pointers & Objects
// FILENAME: CS215Lab1.cpp
// PREPARED FOR: CS215, Section CSGA
// PROGRAMMER(S): Kris Armstrong
// DEVELOPMENT DATE: 10/20/2011
// COMPILER USED: Xcode 4.2
// TARGET PLATFORM: MACBook Pro 17 Early 2009
//================================================================
// PROJECT FILES
// <LIST ALL PROGRAM AND HEADER FILES IN THE PROJECT HERE>
// CS215Lab1.cpp
// cdrom.h
// cdrom.cpp
// cdromsupport.h
// cdromsupport.cpp
//
//================================================================
// REVISION HISTORY
// List revisions made to the Program
//
// DATE PROGRAMMER DESCRIPTION OF CHANGES MADE
// 10/20/11 Kris Armstrong Original
//
//================================================================
//================================================================
// PROGRAM DESCRIPTION
// Enter a brief description of the program here.
// It should be long enough to indicate to the next programmer who works
// with your code exactly what the program does.
// This should normally be form a few sentences to a few paragraphs.
//
// INPUTS: <Describe all outside data that is entered into the program here>
//
// OUTPUTS: <Describe all the outputs, reports, etc., that are generated by
// the program here.>
//
//================================================================
// INCLUDE FILES
#include <iostream>
#include "cdrom.h"
#include "cdromsupport.h"
using namespace std;
//
//================================================================
// CONSTANT DEFINITIONS
// <Constants which apply only to the file>
//
int const NUM_CDROMS = 3;
//
//================================================================
// EXTERNAL CLASS VARIABLES
//
//================================================================
//*****************************************************************************
// BEGINNING OF PROGRAM CODE
//*****************************************************************************
int main ()
{
// Declares 3 CDROM Pointers
CDROM *pCDs[NUM_CDROMS];
// This function "NEWS" and tests for proper DMA
for (int i = 0; i < NUM_CDROMS; i++)
{
pCDs[i] = new CDROM;
if (pCDs[i] == NULL)
{
cout << "Dynamic Memory Allocation FAILED" << endl;
exit(1);
}
}
// Calls show Cost Function
showCost();
// Calls LoadInfo on each CDROM
for (int i = 0; i < NUM_CDROMS; i++)
{
pCDs[i]->loadInfo();
}
// Calls displayInfo on each CDROM
for (int i = 0; i < NUM_CDROMS; i++)
{
pCDs[i]->displayInfo();
}
// Calls Give Memory back function
giveMemoryBack(pCDs, NUM_CDROMS);
return 0;
}
//*****************************************************************************
// END OF PROGRAM CODE FILE
//*****************************************************************************
//*****************************************************************************
//*****************************************************************************
// TITLE: Pointers & Objects
// FILENAME: cdromsupport.h
// PREPARED FOR: CS215, Section CSGA
// PROGRAMMER(S): Kris Armstrong
// DEVELOPMENT DATE: 10/20/2011
// COMPILER USED: Xcode 4.2
// TARGET PLATFORM: MACBook Pro 17 Early 2009
//================================================================
// PROJECT FILES
// <LIST ALL PROGRAM AND HEADER FILES IN THE PROJECT HERE>
// CS215Lab1.cpp
// cdrom.h
// cdrom.cpp
// cdromsupport.h
// cdromsupport.cpp
//
//================================================================
// REVISION HISTORY
// List revisions made to the Program
//
// DATE PROGRAMMER DESCRIPTION OF CHANGES MADE
// 10/20/11 Kris Armstrong Original
//
//================================================================
//******************************************************************************
// PROCESS THIS FILE ONLY ONCE PER PROJECT
//
#ifndef cdromsupport_h //Preprocessor directives to prevent duplicate
#define cdromsupport_h // declarations. Use the file name of the identifier
//substituting an _ underscore for the period
//================================================================
// CONSTANT DEFINITIONS
// <Constants which apply only to the file>
//
//================================================================
// GLOBAL CONSTANTS & OBJECTS
// <Variables and Constants exported to other files>
//================================================================
//*****************************************************************************
// Function Prototypes to (giveMemoryBack)
//*****************************************************************************
void giveMemoryBack(CDROM* pCDs[], int num);
//*****************************************************************************
// Function Prototypes to (showCost)
//*****************************************************************************
int showCost (CDROM *pCDROM1, CDROM *pCDROM2, CDROM *pCDROM3);
//*****************************************************************************
// END OF CONDITIONAL BLOCK
#endif
//*****************************************************************************
// END OF HEADER FILE
//*****************************************************************************
//*****************************************************************************
// TITLE: Pointers & Objects
// FILENAME: cdromsupport.cpp
// PREPARED FOR: CS215, Section CSGA
// PROGRAMMER(S): Kris Armstrong
// DEVELOPMENT DATE: 10/20/2011
// COMPILER USED: Xcode 4.2
// TARGET PLATFORM: MACBook Pro 17 Early 2009
//================================================================
// PROJECT FILES
// <LIST ALL PROGRAM AND HEADER FILES IN THE PROJECT HERE>
// CS215Lab1.cpp
// cdrom.h
// cdrom.cpp
// cdromsupport.h
// cdromsupport.cpp
//
//================================================================
// REVISION HISTORY
// List revisions made to the Program
//
// DATE PROGRAMMER DESCRIPTION OF CHANGES MADE
// 10/20/11 Kris Armstrong Original
//
//================================================================
// CLASSES, FREE, AND FRIEND FUNCTIONS IMPLEMENTED
// class Entry
// Definition of class Entry for a phone directory.
//
//*****************************************************************************
// CONSTANTS
//
//*****************************************************************************
// STANDARD AND USER DEFINED INCLUDES
#include "cdrom.h"
#include "cdromsupport.h"
//*****************************************************************************
// Definition of member functions for class Entry
//*****************************************************************************
//
//---------- Overloaded (friend) I/O operators ----------
// Function to return DMA
//*****************************************************************************
// This Function is used to return the DMA Back to the OS
//*****************************************************************************
void giveMemoryBack(CDROM* pCDs[], int num)
{
CDROM *pTempCDROM = NULL;
for ( int k = 0; k < num; k++)
{
pTempCDROM = pCDs[k];
delete pTempCDROM;
}
}
//*****************************************************************************
// This function is used to compute the total cost and average cost of each
// cdrom
//*****************************************************************************
void showCost(CDROM* pCDs[], tmp = pCDS[i]->returnCost();
{
float total = 0;
float avg = 0;
for (int i = 0; i < 3; i++)
{
}
//*****************************************************************************
// END OF PROGRAM CODE FILE
//*****************************************************************************
//*****************************************************************************
//*****************************************************************************
// TITLE: Pointers & Objects
// FILENAME: cdrom.cpp
// PREPARED FOR: CS215, Section CSGA
// PROGRAMMER(S): Kris Armstrong
// DEVELOPMENT DATE: 10/20/2011
// COMPILER USED: Xcode 4.2
// TARGET PLATFORM: MACBook Pro 17 Early 2009
//================================================================
// PROJECT FILES
// <LIST ALL PROGRAM AND HEADER FILES IN THE PROJECT HERE>
// CS215Lab1.cpp
// cdrom.h
// cdrom.cpp
// cdromsupport.h
// cdromsupport.cpp
//
//================================================================
// REVISION HISTORY
// List revisions made to the Program
//
// DATE PROGRAMMER DESCRIPTION OF CHANGES MADE
// 10/20/11 Kris Armstrong Original
//
//================================================================
// STANDARD AND USER DEFINED INCLUDES
#include <string>
using namespace std;
//******************************************************************************
// PROCESS THIS FILE ONLY ONCE PER PROJECT
//
#ifndef CDROM_H //Preprocessor directives to prevent duplicate
#define CDROM_H // declarations. Use the file name of the identifier
//substituting an _ underscore for the period
//================================================================
// CONSTANT DEFINITIONS
// <Constants which apply only to the file>
//
//================================================================
// GLOBAL CONSTANTS & OBJECTS
// <Variables and Constants exported to other files>
//================================================================
//*****************************************************************************
// Class declaration for CDROM
//*****************************************************************************
class CDROM
{
public: // available outside of class
CDROM(); // constructor hard code initilized data members
void loadInfo(); // Prompts For Input, Validates and set all data members
void displayInfo(); // Display To The screen the values in the data members in a neatly organized way
void changeData(); // Interactively change the data in the calling object similar to lad information exept the old information is being selectively over written
float returnCost() const; // Retun the value in the cost member data
private: // Only available inside class
void setName(); // Used to set the name
void setCost(); // Used to set the cost
void setType(); // Sets CDROM Type
string name; // Name of The CDROM i.e "Myst"
string cdType; // Game, Word, Compiler, Spreadsheet, DBase, Presentation
float cost; // sets variable cost as a float
};
//*****************************************************************************
// END OF CONDITIONAL BLOCK
#endif
//*****************************************************************************
// END OF HEADER FILE
//*****************************************************************************
//*****************************************************************************
// TITLE: Pointers & Objects
// FILENAME: cdrom.cpp
// PREPARED FOR: CS215, Section CSGA
// PROGRAMMER(S): Kris Armstrong
// DEVELOPMENT DATE: 10/20/2011
// COMPILER USED: Xcode 4.2
// TARGET PLATFORM: MACBook Pro 17 Early 2009
//================================================================
// PROJECT FILES
// <LIST ALL PROGRAM AND HEADER FILES IN THE PROJECT HERE>
// CS215Lab1.cpp
// cdrom.h
// cdrom.cpp
// cdromsupport.h
// cdromsupport.cpp
//
//================================================================
// REVISION HISTORY
// List revisions made to the Program
//
// DATE PROGRAMMER DESCRIPTION OF CHANGES MADE
// 10/20/11 Kris Armstrong Original
//
//================================================================
// CLASSES, FREE, AND FRIEND FUNCTIONS IMPLEMENTED
// class Entry
// Definition of class Entry for a phone directory.
//
//*****************************************************************************
// CONSTANTS
//
//*****************************************************************************
// STANDARD AND USER DEFINED INCLUDES
#include <iostream>
#include "cdrom.h"
#include <iomanip>
using namespace std;
//*****************************************************************************
// Constructor For CLASS CDROM
//*****************************************************************************
CDROM::CDROM(): cost(0.0), cdType(""), name("")
{
}
//*****************************************************************************
// This Function is used to set the CDROM Name
//*****************************************************************************
void CDROM::setName()
{
cout << "Please enter name : ";
getline(cin, name);
cin.clear();
cin.ignore(cin.rdbuf()->in_avail(), '\n');
}
//*****************************************************************************
// This Function is used to set the CDROM Cost
//*****************************************************************************
void CDROM::setCost()
{
while (true)
{
cout << "Please Enter Cost: $";
cin >> cost;
if (cost <= 0 || cin.fail())
{
cout << "Invalid cost." << endl;
cin.clear();
cin.ignore(cin.rdbuf()->in_avail(), '\n');
}
else
{
cin.clear();
cin.ignore(cin.rdbuf()->in_avail(), '\n');
break;
}
}
}
//*****************************************************************************
// This Function is used to set the CDROM Type
//*****************************************************************************
void CDROM::setType()
{
while (true)
{
cout << "Please Enter Type: Valid Choses Are (Game, Word, Compiler, Spreadsheet, DBase, Presentation : ";
getline(cin, cdType);
cin.clear();
cin.ignore(cin.rdbuf()->in_avail(), '\n');
if (cdType != "Game" && cdType != "Word" && cdType !="Compiler" && cdType !="Spreadsheet" && cdType !="DBase" && cdType !="Presentation")
{
cout << "Invalid Type" << endl;
}
else
{
break;
}
}
}
//*****************************************************************************
// This Function is used to Return the Cost of the CDROM
//*****************************************************************************
float CDROM::returnCost() const
{
return cost;
}
//*****************************************************************************
// This Function is used display the CDROM Data
//*****************************************************************************
void CDROM::displayInfo() //Function to display current CDROM Info
{
cout << "Current CDROM listings are as follows:" << endl;
cout << "Name: " << name << endl;
cout << "Type: " << cdType << endl;
cout << "Cost: " << /*setprecision(2) <<*/ "$ " << cost << endl;
}
//*****************************************************************************
// This Function is used to Load CDROM Data
//*****************************************************************************
void CDROM::loadInfo()
{
setName();
setType();
setCost();
}
//*****************************************************************************
// This function is used to change the Data of the CDROM
//*****************************************************************************
void CDROM::changeData()
{
cout << "Change Name: (Y/N)";
string change;
cin >> change;
if ((change == "Y" || (change == "y")))
{
setName();
cin.clear();
cin.ignore(cin.rdbuf()->in_avail(), '\n');
}
cout << "Change Type: (Y/N)";
cin >> change;
if ((change == "Y" || (change == "y")))
{
setType();
cin.clear();
cin.ignore(cin.rdbuf()->in_avail(), '\n');
}
cout << "Change Cost: (Y/N)";
cin >> change;
if ((change == "Y" || (change == "y")))
{
setCost();
cin.clear();
cin.ignore(cin.rdbuf()->in_avail(), '\n');
}
}
//*****************************************************************************
// END OF PROGRAM CODE FILE
//*****************************************************************************
//*****************************************************************************