Topic: Computer Science (College Intro) | C++ Programming Here is my code and wh
ID: 3858246 • Letter: T
Question
Topic: Computer Science (College Intro) | C++ Programming Here is my code and whenever i hover over the first line #include "product.h" it says cannot open source file product.h why is this happening and what is the solution? I am using visual studio 2012 ultimate. This is c++ programming. This is the error i received when i try to build my output 1>------ Build started: Project: ConsoleApplication21, Configuration: Debug Win32 ------ 1> Source.cpp 1>c:userssunenadocumentsisual studio 2012projectsconsoleapplication21consoleapplication21source.cpp(1): fatal error C1083: Cannot open include file: 'product.h': No such file or directory ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========
#include "product.h"
#include
#include
#include
using namespace std;
Product::Product()
{
plu = 0;
productName = "none yet";
type = 0;
price = 0;
inventory = 0;
}
Product::Product(int pl, string pn, int t, double pr, double i)
{
plu = pl;
productName = pn;
type = t;
price = pr;
inventory = i;
}
int Product::get PLU()
{ return plu;}
string Product::getProductName()
{ return productName;}
int Product::getType()
{ return type;}
double Product::getPrice()
{ return price;}
double Product::getInventory()
{ return inventory;}
double Product::updateInventory(double quantity)
{
if (quantity > inventory)
cout << "This item is not in stock." << endl;
else inventory -= quantity;
return inventory;
}
Here is my code
Explanation / Answer
I think this is because you are missing a header file whose name should be product.h.
Below is the header file I created.
after adding it , it compiles perfectly fine.
product.h
#ifndef _PRODUCT_H
#define _PRODUCT_H
#include <iostream>
using namespace std;
class Product {
private:
int plu;
string productName;
int type;
double price;
double inventory;
public:
Product(int pl, string pn, int t, double pr, double i);
Product();
int getPLU();
string getProductName();
int getType();
double getPrice();
double getInventory();
double updateInventory(double quantity);
};
#endif
product.cpp
#include "product.h"
using namespace std;
Product::Product()
{
plu = 0;
productName = "none yet";
type = 0;
price = 0;
inventory = 0;
}
Product::Product(int pl, string pn, int t, double pr, double i)
{
plu = pl;
productName = pn;
type = t;
price = pr;
inventory = i;
}
int Product::getPLU()
{ return plu;}
string Product::getProductName()
{ return productName;}
int Product::getType()
{ return type;}
double Product::getPrice()
{ return price;}
double Product::getInventory()
{ return inventory;}
double Product::updateInventory(double quantity)
{
if (quantity > inventory)
cout << "This item is not in stock." << endl;
else inventory -= quantity;
return inventory;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.