Question

What is wrong with this header file? The program wont compile but if i transfer the...

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

Homework Answers

Answer #1

#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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
IN JAVA Language- Singly Linked List Implementation Implement a Linked List in your language. Use your...
IN JAVA Language- Singly Linked List Implementation Implement a Linked List in your language. Use your Can class. You need to create a driver that makes several Can objects and places them in alphabetical order in a list. Identify the necessary methods in a List Linked implementation. Look at previous Data Structures (stack or queue) and be sure to include all necessary methods. NOT USE your language's Library List . You will receive zero points. Write a LinkedList class. Include...
No matter what I do I cannot get this code to compile. I am using Visual...
No matter what I do I cannot get this code to compile. I am using Visual Studio 2015. Please help me because I must be doing something wrong. Here is the code just get it to compile please. Please provide a screenshot of the compiled code because I keep getting responses with just code and it still has errors when I copy it into VS 2015: #include <iostream> #include <conio.h> #include <stdio.h> #include <vector> using namespace std; class addressbook {...
do (iii) and (iv) (i) This is a simple Point class interface file whose objects represent...
do (iii) and (iv) (i) This is a simple Point class interface file whose objects represent points in the cartesian plane #include <iostream> using namespace std; class Point { public:     Point()      // default constructor         Point(double x, double y); // another constructor         double x() const; // get function, return _x         double y() const; // get function, return _y private:         double _x, _y; }; (ii) Here is a test driver file for the Point class...
what am i doing wrong here ? starting out with c++ early objects 9th edition chapter...
what am i doing wrong here ? starting out with c++ early objects 9th edition chapter 10 programming challenge 6 #include <iostream> using namespace std; int main() {       double findMedian(int* numbers, int size) {    double median;    if (size % 2 == 0)        median = (double)(*(numbers + ((size - 1) / 2))            + *(numbers + (((size - 1))) / 2;    else                median = *(numbers + ((size -...
can someone edit my c++ code where it will output to a file. I am currently...
can someone edit my c++ code where it will output to a file. I am currently using xcode. #include <iostream> #include <cctype> #include <cstring> #include <fstream> using namespace std; bool inputNum(int [],int&,istream&); void multiply(int[],int,int[],int,int[],int&); void print(int[],int,int,int); int main() {ifstream input; int num1[35],num2[35],len1,len2,num3[60],len3=10,i; input.open("multiplyV2.txt"); //open file if(input.fail()) //is it ok? { cout<<"file did not open please check it\n"; system("pause"); return 1; }    while(inputNum(num1,len1,input)) {inputNum(num2,len2,input); multiply(num1,len1,num2,len2,num3,len3); print(num1,len1,len3,1); print(num2,len2,len3,2); for(i=0;i<len3;i++) cout<<"-"; cout<<endl; print(num3,len3,len3,1); //cout<<len1<<" "<<len2<<" "<<len3<<endl; cout<<endl;    } system("pause"); } void...
// This program prints a table to convert numbers from one unit to another. // The...
// This program prints a table to convert numbers from one unit to another. // The program illustrates some implementation techniques. //Include the header file ostream for including all stream. ---------------------------------------------------------*/ #include <iostream> //Provides cout <v1.0> //Include iomanip that is used for set precision. #include <iomanip> //Provides setw function for setting output width <v1.1> //Header file for EXIT_SUCCESS. #include <stdlib.h>// Provides EXIT_SUCCESS <v1.2> //Header file for assert. #include <assert.h>// Provides assert function <1.3> using namespace std; // Allows all standard...
Whenever I try to run this program a window appears with Class not Found in Main...
Whenever I try to run this program a window appears with Class not Found in Main project. Thanks in Advance. * * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package Assignment10; /** * * @author goodf */ public class Assignment10{ public class SimpleGeometricObject { private String color = "white"; private boolean filled; private java.util.Date dateCreated;    /**...
Write a template-based class that implements a template-based implementation of Homework 3 that allows for any...
Write a template-based class that implements a template-based implementation of Homework 3 that allows for any type dynamic arrays (replace string by the template in all instances below). • The class should have: – A private member variable called dynamicArray that references a dynamic array of type string. – A private member variable called size that holds the number of entries in the array. – A default constructor that sets the dynamic array to NULL and sets size to 0....
C++ programming Write a program that reads a comma-separated file (CSV) with integer values and prints...
C++ programming Write a program that reads a comma-separated file (CSV) with integer values and prints the number of integer values in the file. Your program's input will be a string with the name of the file. If the file does not exist, then the program must print: Error opening the file For example, given the following CSV file input1.csv: 1,10,20,30,40 The output of your program must be: 5 You can safely assume that the input file will be a...
C++ PROGRAM When I input 3 S P R, it was suppoesed to pop up L...
C++ PROGRAM When I input 3 S P R, it was suppoesed to pop up L W T. But it showed L L L.IDK why the moveNo is not working. I am asking for help, plz dont put some random things on it. main.cpp #include <iostream> #include "computer.h" #include "human.h" #include "referee.h" using namespace std; int main() {     human h;     computer c;     referee r;     r.compare(h,c);     return 0; } computer.cpp #include<iostream> #include "computer.h" using namespace std;...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT