I am trying to write a program that manages a stores backend (i.e. keeping track of customers and products). I just started learning c++ in January and I am definitely a beginner with regards to classes and separate header files and such. I am getting a few undeclared identifier errors and a couple of unknown type name errors.
I am very aware that the code is rough, I am just trying to tackle this and get a good grip on how these interactions occur.
The main.cpp is MIA because it is hidden by a testing function created by my instructor.
The errors being received are as follows: https://i.stack.imgur.com/qymeo.jpg The locations of these errors are marked in the code by comments in order. Thank you so much in advance for any help, just want to get better at this.
Store.h
#ifndef Store_h
#define Store_h
#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <vector>
class Store{
std::vector<Product*> products; //Error 1-2
std::vector<Customer*> customers; //Error 3-4
public:
Store();
Store(std::string name);
std::string getStorename();
void setStorename(std::string name);
void addProduct(int productNum, std::string productName);
Customer* getCustomer(int customerID); //Error 5
void addCustomer(int customerID, std::string name, bool credit);
Product* getProduct(int productNum); //Error 6
void takeShipment(int productNum, int quantity, double cost);
void makePurchase(int customerID, int productNum, int quantity);
void takePayment(int customerID, double amount);
void listProducts();
void listCustomers();
private:
std::string name;
};
#endif /* Store_h */
Store.cpp
#include <iostream>
#include "Store.h"
#include "Product.h"
#include "Customer.h"
using namespace std;
Store::Store(){
}
Store::Store(string name): name(name) {
}
void Store::setStorename(string name) {
this->name = name;
}
string Store::getStorename(){
return name;
}
void Store::addProduct(int productNum, string productName){
Product* prod = new Product(productNum, productName);
products.push_back(prod);
}
Product* Store::getProduct(int productNum){
for (int i = 0; i < products.size(); ++i) {
Product* a = products.at(i);
if (a->getProductNum() == productNum) {
return a;
}
}
throw runtime_error("Invalid Product.");
}
void Store::addCustomer(int customerID, string name, bool credit){
Customer* cust = new Customer(name, customerID, credit);
customers.push_back(cust);
}
Customer* Store::getCustomer(int customerID){
for (int i = 0; i < customers.size(); ++i) {
Customer* a = customers.at(i);
if (a->getID() == customerID) {
return a;
}
}
throw runtime_error("Invalid Customer.");
}
void Store::takeShipment(int productNum, int quantity, double cost){
for (int i = 0; i < products.size(); ++i) {
Product* a = products.at(i);
if (a->getProductNum() == productNum) {
}
}
throw runtime_error("Invalid Product.");
}
void Store::makePurchase(int customerID, int productNum, int quantity){
Customer* a = getCustomer(customerID);
a->processPurchase(productNum, product); //ERROR 'use of undeclared
// variable 'product'
}
void Store::takePayment(int customerID, double amount){
Customer* a = getCustomer(customerID);
a->processPayment(amount);
}
void Store::listProducts(){
for (int i = 0; i < products.size(); ++i) {
Product* prod = products.at(i);
prod->getInfo();
cout << endl;
}
}
void Store::listCustomers(){
for (int i = 0; i < customers.size(); ++i) {
Customer* prod = customers.at(i);
prod->getInfo();
cout << endl;
}
}
Product.h
#ifndef Product_h
#define Product_h
#pragma once
#include <stdio.h>
#include "Customer.h"
#include "Store.h"
#include <string>
#include <iostream>
#include <vector>
class Product{
public:
Product();
Product(int productNum, std::string productName);
void setDescription(std::string description);
std::string getDescription();
void setDefaultReturnPeriod(int days);
int getReturnPeriod();
int getNumberSold();
double getTotalCost();
void addShipment(int quantity, double cost);
double getPrice();
void processOrder(int quantity);
int getProductNum();
void getInfo();
protected:
std::string productName;
private:
int productNum;
int inventory;
int numSold;
int totalCost;
std::string description;
int defaultReturnDays;
int quantity;
double cost;
};
#endif /* Product_h */
Customer.h
#ifndef Customer_h
#define Customer_h
#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include "Store.h"
#include <vector>
class Customer{
public:
Customer();
Customer(std::string name, int customerID, bool credit);
void setName(std::string name);
std::string getName();
int getID();
void setCredit(bool hasCredit);
bool getCredit();
double getBalance();
void processPayment(double amount);
void processPurchase(double amount, Product product); //Error 7
void getInfo();
private:
std::string memberName;
std::string name;
int customerID;
bool credit;
double balance;
std::vector<Product*> productsPurchased; //Error 8
};
#endif /* Customer_h */