What is wrong with this header file? The program wont compile but if i transfer the body of the header file into the main file it will compile just fine.
This is the error message that pops up: [Error] 'cout' was not declared in this scope
// Specification file for the Account class.
#ifndef ITEM_H
#define ITEM_H
#include <string>
using std::string;
class Can
{
private:
double price = 0.0;
string company;
string content;
double size = 0.0;
public:
Can()
{
price =
0.99;
company =
"Goyo";
content = "Black
Beans";
size =
13.0;
}
Can(double p, double s, string com,
string cont)
{
price = p;
size = s;
company =
com;
content =
cont;
}
Can(string com, string cont)
{
company =
com;
content =
cont;
}
double getPrice()
{
return
price;
}
string getCompany()
{
return
company;
}
string getContent()
{
return
content;
}
double getSize()
{
return
size;
}
void setPrice(double p)
{
price = p;
}
void setCompany(string com)
{
company =
com;
}
void setContent(string cont)
{
content =
cont;
}
void setSize(double s)
{
size = s;
}
void displayArray()
{
cout <<
"[Company = " << company << ", Content = " <<
content << ", Size = " << size << ", Price = "
<< price << "]";
}
};
#endif
This is the main file that goes with it
#include <iostream>
#include <string>
#include "item.h"
using namespace std;
int main()
{
Can can1;
Can can2(2.39, 12.0, "S&W", "Peaches"), can3(1.79,
11.9, "Green Giant", "Green beans"), can4("Del Monte", "Creamed
Corn");
can4.setPrice(2.49);
can4.setSize(13.4);
cout << "Can 1: Can ";
can1.displayArray();
cout << "\nCan 2: Can ";
can2.displayArray();
cout << "\nCan 3: Can ";
can3.displayArray();
cout << "\nCan 4: Can ";
can4.displayArray();
return 0;
}
Thanks
#ifndef ITEM_H #define ITEM_H #include <string> using std::string; using std::cout; class Can { private: double price = 0.0; string company; string content; double size = 0.0; public: Can() { price = 0.99; company = "Goyo"; content = "Black Beans"; size = 13.0; } Can(double p, double s, string com, string cont) { price = p; size = s; company = com; content = cont; } Can(string com, string cont) { company = com; content = cont; } double getPrice() { return price; } string getCompany() { return company; } string getContent() { return content; } double getSize() { return size; } void setPrice(double p) { price = p; } void setCompany(string com) { company = com; } void setContent(string cont) { content = cont; } void setSize(double s) { size = s; } void displayArray() { cout << "[Company = " << company << ", Content = " << content << ", Size = " << size << ", Price = " << price << "]"; } }; #endif
Get Answers For Free
Most questions answered within 1 hours.