Can someone tell me why I'm getting a segmentation fault (core dumped)? After I compile my code, I'm only able to to input the last cin before I get segmentation fault (core dumped) message.
Thank you.
Note: I did this w/o pointers as I'm doing problems out of my book and have not arrived to pointers yet.
Inventory.hpp
#ifndef INVENTORY_H
#define INVENTORY_H
class Inventory
{
//member variables
private:
int itemNumber, quantity;
double cost;
//member functions
public:
Inventory();
Inventory(int, int, double);
void setItemNumber(int); //beginning of setter funtions
void setQuantity(int);
void setCost(double);
int getItemNumber(); //beginning of getter functions
int getQuantity();
double getCost();
double getTotalCost(); //made this a double on purpose
};
#endif
Inventory.cpp (implementation file)
#include "Inventory.hpp" //include statement for class Inventory
#include <iostream>
/*********************
**Description: Default Constructor
*********************/
Inventory::Inventory()
{
setItemNumber(000);
setQuantity(000);
setCost(000);
}
/**********************
**Description: Constructor that accepts all member variables as arguments.
**Calls other class functions to copy these values into appropriate member
**variables. Then calls the setTotalCost fuction.
***********************/
Inventory::Inventory(int iN, int q, double c)
{
setItemNumber(iN); //using set method
setQuantity(q);
setCost(c);
}
/***********************
**Description: The next 3 functions are setter functions
***********************/
void Inventory::setItemNumber(int iN)
{
setItemNumber(iN);
}
void Inventory::setQuantity(int q)
{
setQuantity(q);
}
void Inventory::setCost(double c)
{
setCost(c);
}
/********************
**Description: The next 4 functions are getter functions
*********************/
int Inventory::getItemNumber()
{
return itemNumber;
}
int Inventory::getQuantity()
{
return quantity;
}
double Inventory::getCost()
{
return cost;
}
double Inventory::getTotalCost()
{
return quantity * cost;
}
inventoryMain.cpp
#include "Inventory.hpp"
#include <iostream>
#include <iomanip>
using std::cout;
using std::cin;
using std::endl;
using std::fixed;
using std::setprecision;
int main ()
{
int iN, q;
double c;
cout << "Please enter the item number.\n";
cin >> iN;
cout << "Please enter the quantity.\n";
cin >> q;
cout << "Please enter the cost.\n";
cin >> c;
//create class object and set it with user inputs as arguments