0

Specifications (minimum):

The CDROM class contains the following, private, data members:
string Name; // The Name of the CDROM
string CDType; // The Type of CDROM
float Cost; // The Cost of the CDROM

The ONLY recognized (i.e., legal) CDROM types are, “Game”, “Word”, “Compiler”, “Spreadsheet”, “Dbase”, and “Presentation” (AND, no others!).

The CDROM class contains the following, public, member functions:

CDROM();
// Constructor – hard-code initializes data members

void LoadInformation();
// Prompt for, input, validate and set all data members

float ReturnCost();
// Return the value in the Cost member data.

void DisplayInformation();
// Display to the screen the values in the data members in a neatly organized manner.

void ChangeData();
// Interactively change the data in the calling object - similar to LoadInformation(), except the old information is being selectively overwritten.

* Since the instructor has allowed them, I've added in some helper mutators to set the information.

I've written the header and cpp files for the class, but I could use help in debugging it while still maintaining the specs of the assignment.

Specifically, the error codes I get for these two files are:
1> CDROM.cpp
1>\cdrom.cpp(103): error C2511: 'float CDROM::ReturnCost(void) const' : overloaded member function not found in 'CDROM'
1>\cdrom.h(40) : see declaration of 'CDROM'
1>cdrom.cpp(108): error C2511: 'void CDROM::DisplayInformation(void) const' : overloaded member function not found in 'CDROM'
1>\cdrom.h(40) : see declaration of 'CDROM'

How do I set up ReturnCost() & DisplayInformation() so that they aren't coming up as an overloaded function?

My Header Code

#ifndef CDROM_H					// allows for additional headers
#define CDROM_H
//=============================================================================
//             INCLUDE FILES
#include <string>
//
//=============================================================================
//              Class Object

class CDROM

//============================================================================
{
public:						// available outside of class
		CDROM();			// SMF to set value
		void LoadInformation();		// member functions
		float ReturnCost();
		void DisplayInformation();
		void ChangeData() ;
	
private:					// not available outside class
		void SetName();			// Special Helper Mutators
		void SetCost();
		void SetType();
private:					// Like paragraph indicators - useful to separate things
		std::string Name;		// The NAME of the CDROM
		std::string CDType;		// The TYPE of CDROM - Game, Word, Compiler, 
		std::string Type;		// Spreadsheet, DBase, and Presentation
		float Cost;
};

//=============================================================================
//            	END OF CONDITIONAL BLOCK
#endif

My CPP code for the Class:

// 				INCLUDE FILES
#include "CDROM.h"				// for processing CDROM class
#include <iostream>				// for io processing
using namespace std;
//
//=============================================================================
//					CONSTANT DEFINITIONS
//
//=============================================================================
//					EXTERNAL CLASS VARIABLES
//
//=============================================================================
//*****************************************************************************
// 				BEGINNING OF PROGRAMMING CODE
//*****************************************************************************
CDROM::CDROM() : Cost(0.0), CDType( "6. Presentation" )
{
}
void CDROM::SetName()					// Helper functions to do the work of getting,
{	                                                // validating, and displaying the user data.										
	cout << "Enter Name:" << endl;			
	cin >> Name;					// This will allow good reuse in LoadInformation() 
}                                                       // & ChangeData().											      

void CDROM::SetCost()					// Needs validation since its a float
{											                                
for ( ;; )						// This will keep the user in the input loop until 
                                                        // they enter a valid float for Cost.
{
cout << "Enter Cost:" << endl;
cin >> Cost;
if ( !cin || cin.gcount( ) != 1 )
{
cout << "Invalid Cost." << endl;
}
else
{
break;
}
}
}

void CDROM::SetType()					// Tricky mutator - have to check it against Each type listed
{
	for (;;)
	{
		cout << "Enter Type:" << endl;
		cin >> Type;
		if (Type != "Game" && Type != "Word" && Type !="Compiler" && Type !="Spreadsheet" && Type !="DBase" && Type !="Presentation")
		{
			cout << "Invalid Type." << endl;
		}
		else
		{
			break;
		}
	}
}


void CDROM::LoadInformation()
{
	cout << "Enter CDROM Information:" << endl;
	SetName( );								
	SetType( );								
	SetCost( );								
}
float CDROM::ReturnCost() const				 // Not changing data - make const.
											// A good rule of thumb, const by default - 
											//justify why it isn't.
{
	return Cost;
}
void CDROM::DisplayInformation() const		         // Again, doesn't modify any data member or call any const methods of the class
{
	cout <<"Current CDROM Listings Are As Follows: " << endl;
	cout << "Name: " << Name << endl;
	cout << "Type: " << CDType << endl;
	cout << "Cost: " << setprecision(2) << "$ " << Cost << endl;
}
void CDROM::ChangeData()
{
	cout << "Change Name? (Y/N)";
	char change;
	cin >> change;
	if ((change == 'Y') || (change == 'y'))
	{
		SetName();
	}
	cout << "Change Type? (Y/N)";
	cin >> change;
	if ((change == 'Y') || (change == 'y'))
	{
		SetType();
	}
	cout << "Change Cost? (Y/N)";
	cin >> change;
	if ((change == 'Y') || (change == 'y'))
	{
		SetCost();
	}
}
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by mitrmkar
0

>> float CDROM::ReturnCost(void) const' : overloaded member function not found in 'CDROM'

It's saying that the function declaration/definition signatures are not matching wrt. your const usage, so you want to have ..

class CDROM
{
...
 float ReturnCost() const; // <--- const was missing
 // The same thing for the other function
...
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.