I have to create two classes CPU and Computer. The CPU.h and Computer.h needs to be different files than the CPU.cpp and Computer.cpp. I believe I created my files correctly however in my Computer constructor, I'm told to "allocates memory for the pointer of of CPU (i.e., call the constructor of the CPU class)." I'm not sure if I'm doing that right because I get the error 13 invalid use of `class CPU' , I bolded the line which it happens on
Heres Computer.cpp:
Code:
//File Computer.cpp
#include <string>
#include<iostream>
#include "CPU.h"
#include "Computer.h"
Computer:: Computer()
{
brandName = "?";
memory = 0;
price = 0.0;
*cpu->CPU();
}
Computer:: ~Computer()
{
cout<<"The computer "<<brandName<<" is getting destroyed."<<endl;
free(cpu);
}
string Computer:: getBrandName()
{
return brandName;
}
CPU * Computer:: getCPU()
{
return cpu;
}
int Computer:: getMemory()
{
return memory;
}
double Computer:: getPrice()
{
return price;
}
void Computer:: setBrandName(string BrandName)
{
brandName = BrandName;
}
void Computer:: setCPU(string cpuType, int cpuSpeed)
{
cpu->setType(cpuType);
cpu->setSpeed(cpuSpeed);
}
void Computer:: setMemory(int memoryAmount)
{
memory = memoryAmount;
}
void Computer:: setPrice(double price)
{
price = price;
}
void Computer:: printInfo()
{
cout<<"\nBrandName:\t"<<brandName<<"\nCPU:\t\t"<<cpu->getType()<<","
<<cpu->getSpeed()<<"HZ\nMemory:\t\t"<<memory<<"M\nPrice:\t\t$"<<price
<<"\n\n";
}
Heres Computer.h:
Code:
//File Computer.h
#include <string>
#include "CPU.h"
//#include <iostream>
using namespace std;
#ifndef Computer_H
#define Computer_H
class Computer
{
private:
string brandName;
CPU * cpu;
int memory;
double price;
public:
Computer();
~Computer();
string getBrandName();
CPU* getCPU();
int getMemory();
double getPrice();
void setBrandName(string);
void setCPU(string, int);
void setMemory(int);
void setPrice(double);
void printInfo();
};
#endif
Heres CPU.h:
Code:
// File CPU.h
#include <string>
using namespace std;
#ifndef CPU_H
#define CPU_H
class CPU
{
private:
string type;
int speed;
public:
CPU();
~CPU();
string getType();
int getSpeed();
void setType(string);
void setSpeed(int);
void printInfo();
};
#endif
And heres CPU.cpp
Code:
// File CPU.cpp
#include <string>
#include <iostream>
#include "CPU.h"
CPU:: CPU()
{
type = "?";
speed = 0;
}
CPU:: ~CPU()
{
cout<<"CPU with the type "<< type <<" and the speed "<< speed <<" is being destroyed." <<endl;
}
string CPU:: getType()
{
return type;
}
int CPU:: getSpeed()
{
return speed;
}
void CPU:: setType(string type)
{
type = type;
}
void CPU:: setSpeed(int speed)
{
speed = speed;
}
void CPU:: printInfo()
{
cout<<type<<","<<speed<<"HZ"<<endl;
}
Any help would be appreciated