Tuesday, July 14, 2009

Write a C++ program that includes the CPU class interfaces, class definitions, and code that will test your cl

The CPU class is described as follows:


• One attribute:


clockSpeed – a double value representing the clock speed of the CPU object. Note: clock speed of a modern computer may be something like 2.5GHz, so a value you could use for testing purposes is 2.5.


• Two constructors:


A default constructor.


A constructor that initializes the attribute, where cs is the clockSpeed.


• Two methods:


getClockSpeed() – return the clockSpeed value associated with the CPU object.


setClockSpeed(cs) – change the clockSpeed value associated with the CPU object, where cs is the new value.

Write a C++ program that includes the CPU class interfaces, class definitions, and code that will test your cl
-- cpu.h --


class CPU {


double clockSpeed;


public:


CPU( void );


CPU( double cs );


double getClockSpeed( void ) const;


void setClockSpeed( double cd );


};





-- cpu.cpp --


#include "cpu.h"


CPU::CPU( void ) : clockSpeed( 0 ) {}


CPU::CPU( double cs ) : clockSpeed( cs ) {}


double CPU::getClockSpeed( void ) const { return clockSpeed; }


void CPU::setClockSpeed( double cd ) { clockSpeed = cs; }





-- main.cpp --


#include %26lt;iostreams%26gt;


#include "cpu.h"


using namespace std;


int main( int, char ** )


{


CPU cpu1, cpu2( 123.456 );


cpu1.setClockSpeed( 645.321 );


cout %26lt;%26lt; "CPU1 speed: " %26lt;%26lt; cpu1.getClockSpeed() %26lt;%26lt; endl;


cout %26lt;%26lt; "CPU2 speed: " %26lt;%26lt; cpu2.getClockSpeed() %26lt;%26lt; endl;


return 0;


}
Reply:That is lot of work, may be you can contact a C++ expert at websites like http://askexpert.info/

brenda song

No comments:

Post a Comment