I am solving a question of Nested structure in C++ but
I am getting an error in accessing the member function of struct Date i.e: void showdata()
First I have made a Data struct then in it I have added member function called void showdata which will show data of my another Struct Employee. However I can't access this member function in my main program.
ERROR :
Error C2660 'Date::showdata': function does not take 0 arguments
so basically getting an error in the last line of code that is:
d.showdata()
Here's my code:
struct Date
{
int year, month, date;
void showdata(int empid, string name, double salary, int year, int month,int date)
{
cout << "\t\tEmployee's Data:\n";
cout << "Employee ID --> " << empid << endl;
cout << "Employee Name --> " << name << endl;
cout << "Salary --> " << salary << endl;
cout << "Joining Date -- >" << date << "-" << month << "-" << year << endl;
}
};
struct Employee
{
int empid;
string name;
double salary;
Date joiningdate;
};
int main()
{
//Q3
Employee e;
Date d;
cout << "Enter Employee ID = ";
cin >> e.empid;
cout << "Enter Employee Name = ";
cin >> e.name;
cout << "Enter Salary = ";
cin >> e.salary;
cout << "Enter Employee joining year = ";
cin >> e.joiningdate.year;
cout << "Enter Employee joining month = ";
cin >> e.joiningdate.month;
cout << "Enter Employee joining date = ";
cin >> e.joiningdate.date;
d.showdata();
}
Did you mean to move the member function into the Employee class?
struct Date
{
int year, month, date;
};
struct Employee
{
int empid;
string name;
double salary;
Date joiningdate;
void showdata()
{
cout << "\t\tEmployee's Data:\n";
cout << "Employee ID --> " << empid << endl;
cout << "Employee Name --> " << name << endl;
cout << "Salary --> " << salary << endl;
cout << "Joining Date -- >" << joiningdate.date << "-" << joiningdate.month << "-" << joiningdate.year << endl;
}
};
int main()
{
//Q3
Employee e;
cout << "Enter Employee ID = ";
cin >> e.empid;
cout << "Enter Employee Name = ";
cin >> e.name;
cout << "Enter Salary = ";
cin >> e.salary;
cout << "Enter Employee joining year = ";
cin >> e.joiningdate.year;
cout << "Enter Employee joining month = ";
cin >> e.joiningdate.month;
cout << "Enter Employee joining date = ";
cin >> e.joiningdate.date;
e.showdata();
}
You defined the showdata method inside the Date struct to take 6 arguments, yet when invoking the method in main you are supplying 0 arguments. To correctly invoke the showdata method you need to supply it with the correct set of parameters:
d.showdata(e.empid, e.name, e.salary, e.joiningdate.year, e.joiningdate.month, e.joiningdate.date);
Also be sure to check that the parameter types that you are passing in match the argument types that you defined the method to accept.
Related
#include <iostream>
using namespace std;
struct teacher
{
int id;
char name[50];
int salary;
void input(teacher a)
{
cout << "Enter Name : ";
cin >> a.name;
cout << "Enter ID : ";
cin >> a.id;
cout << "Enter Salary : ";
cin >> a.salary;
}
void output(teacher b)
{
cout << "Your Name Is : " << b.name << endl;
cout << "Your ID Is : " << b.id << endl;
cout << "Your Salary Is : " << b.salary;
}
};
int main()
{
teacher t;
t.input(t);
t.output(t);
return 0;
}
Is there any problem? The output is random numbers, don't know what is it.
I tried writing the output function separately, but still same results.
This seems like a weird design, why don't your class methods directly operate on this?
struct teacher
{
int id;
std::string name;
int salary;
void input()
{
cout << "Enter Name : ";
cin >> name;
cout << "Enter ID : ";
cin >> id;
cout << "Enter Salary : ";
cin >> salary;
}
void output() const
{
cout << "Your Name Is : " << name << endl;
cout << "Your ID Is : " << id << endl;
cout << "Your Salary Is : " << salary;
}
};
Then main would look like
int main()
{
teacher t;
t.input();
t.output();
return 0;
}
Also I'd prefer to use std::string instead of char[] when possible.
In input() you modify parameter a which goes out of scope when it reaches the end of the function.
Instead you should modify the class members variables themselves.
void input()
{
cout << "Enter Name : ";
cin >> name;
cout << "Enter ID : ";
cin >> id;
cout << "Enter Salary : ";
cin >> salary;
}
I am to create an application that takes at least 5 employees i.d, names, pay rate, and hours. And then I am to add the pay rate and the hours together to show the gross pay for each employee at the end of the initial inquiries. I am stuck on how to add it in the vector please help!
** Here is the assignment that our instructor gave us **
http://itweb.fvtc.edu/ag/?u=3&f=cpp-assignment4
I've added a vector and added all the essential information for the employee
#include <iostream>
#include <conio.h>
#include <string>
#include <vector>
using namespace std;
struct Employee
{
int id;
string firstName;
string lastName;
float payRate;
int hours;
};
int main()
{
/*========= other way of adding employee information ==========*/
/*const int NUM_EMPLOYEE = 5;
Employee employee[NUM_EMPLOYEE];
for (int i = 0; i < 5; i++)
{
cout << "ID of employee " << (i + 1) << ": ";
cin >> employee[i].id;
cout << "First Name of employee " << (i + 1) << ": ";
cin >> employee[i].firstName;
cout << "Last Name of employee " << (i + 1) << ": ";
cin >> employee[i].lastName;
cout << "Pay rate for employee " << (i + 1) << ": ";
cin >> employee[i].payRate;
cout << "Hours worked " << (i + 1) << ": ";
cin >> employee[i].hours;
}*/
/*========= End of other way of adding employee information ==========*/
vector<Employee> employees;
char Another = 'y';
while (Another == 'y' || Another == 'Y')
{
Employee e;
cout << "Enter employee ID: \n";
cin >> e.id;
cout << "Enter employee first name: \n";
cin >> e.firstName;
cout << "Enter employee last name: \n";
cin >> e.lastName;
cout << "Enter employee pay rate: \n";
cin >> e.payRate;
cout << "Enter employee hours worked: \n";
cin >> e.hours;
employees.push_back(e);
cout << "Another? (y/n): \n";
cin >> Another;
}
float sum = 0;
vector<Employee>::iterator it = employees.begin();
for (; it != employees.end(); it++)
{
cout << "ID of employee: \n" << it->id << ": \n"
<< "Employees name: \n" << it->firstName << " " << it->lastName << ": \n"
<< "Employee pay rate: \n" << it->payRate << ": \n"
<< "Employee hours worked: \n" << it->hours << "\n";
}
float avg = sum / employees.size();
Employee e;
/*cout << " ID of employees: \n" << e.id;
cout << " Name of employees: \n" << e.firstName << " " <<
e.lastName;*/
cout << "Gross pay of employees: \n" << avg;
_getch();
return 0;
}
Show Id, names, and gross pay of all employees to user
vector<Employee> employees;
char Another = 'y';
while (Another == 'y' || Another == 'Y')
{
Employee e;
cout << "Enter employee ID: \n";
cin >> e.id;
cout << "Enter employee first name: \n";
cin >> e.firstName;
cout << "Enter employee last name: \n";
cin >> e.lastName;
cout << "Enter employee pay rate: \n";
cin >> e.payRate;
cout << "Enter employee hours worked: \n";
cin >> e.hours;
employees.push_back(e);
cout << "Another? (y/n): \n";
cin >> Another;
}
float sum = 0;
vector<Employee>::iterator it = employees.begin();
cout << "ID" << "\t" << "First Name" << "\t" << "Last Name" << "\t" << "Pay rate" << "\t" << "Hours" << "\t" << "Gross Pay" << "\n" ;
for (; it != employees.end(); it++)
{
float grossPay = it->payRate * it->hours;
cout << it->id << "\t" << it->firstName << "\t\t" << it->lastName << "\t\t" << it->payRate << "\t\t"
<< it->hours << "$" << "\t" << grossPay << "\n";
sum += grossPay;
}
cout << "The gross pay for all employee is: " << "$" << sum;
_getch();
return 0;
}
//This is what i got so far. But if I want to make the application ask the user to input how many employee they want to enter into the database how do i do that? would it be like this?
int EMPLOYEE_NUM[][] // ??
Okay, so I am writing a C++ program to declare a struct data type that holds the following information on an employee (First Name, Last Name, ID, Pay Rate, and Hours). My problem is that the user can only enter in the ID and First Name, then the whole program runs without letting the user enter the rest of the data.
Heres my code:
#include <iostream>
#include <iomanip>
using namespace std;
struct Employee
{
int employeeID;
char firstName;
char lastName;
float payRate;
int hours;
};
int main()
{
int i, j;
cout << "How Many Employees Do You Wish To Enter?:\n\n";
cin >> j;
Employee info;
for (i = 0; i < j; i++)
{
cout << "Enter in the Data for Employee number " << i + 1 << endl;
cout << setw(5) << "\n Please Enter The Employee ID Number: ";
cin >> info.employeeID;
cout << setw(5) << "\n Please Enter Employees First Name: ";
cin >> info.firstName;
cout << setw(5) << "\n Please Enter Employees Last Name: ";
cin >> info.lastName;
cout << setw(5) << "\n Please Enter Employees Pay Rate: ";
cin >> info.payRate;
cout << setw(5) << "\n Please Enter The Hours The Employee Worked:
";
cin >> info.hours;
}
cout << "\n\n \n";
cout << "ID" << setw(15) << "First Name" << setw(10) << "Last Name" <<
setw(10) << "Pay Rate" << setw(10) << "Hours";
cout << endl;
for (i = 0; i < j; i++)
{
cout << "\n" << info.employeeID << setw(15) << info.firstName << setw(10) << info.lastName << setw(10) << info.payRate << setw(10) << info.hours;
}
cout << "\n\n \n";
system("pause");
return 0;
};
#include <iostream>
#include <iomanip>
#include <string> //Allows you to use strings, which are way more handy for text manipulation
#include <vector> //Allows you to use vector which are meant to be rezied dynamicaly, which is your case
using namespace std;
struct Employee
{
int employeeID;
string firstName; //HERE : use string instead of char (string are array of char)
string lastName; //HERE : use string instead of char
float payRate;
int hours;
};
int main()
{
int j;
cout << "How Many Employees Do You Wish To Enter?:\n\n";
cin >> j;
vector<struct Employee> info; //creation of the vector (dynamic array) to store the employee info the user is going to give you
for (int i = 0; i < j; i++) //declare your looping iterator "i" here, you will avoid many error
{
struct Employee employee_i; // create an employee at each iteration to associate the current info
cout << "Enter in the Data for Employee number " << i + 1 << endl;
cout << "\n Please Enter The Employee ID Number: ";
cin >> employee_i.employeeID;
cout << "\n Please Enter Employees First Name: ";
cin >> employee_i.firstName;
cout << "\n Please Enter Employees Last Name: ";
cin >> employee_i.lastName;
cout << "\n Please Enter Employees Pay Rate: ";
cin >> employee_i.payRate;
cout << "\n Please Enter The Hours The Employee Worked: ";
cin >> employee_i.hours;
info.push_back(employee_i); //store that employee info into your vector. Push_back() methods expands the vector size by 1 each time, to be able to put your item in it
} // because you employee variable was create IN the loop, he will be destruct here, but not the vector which was created outside
cout << "\n\n \n";
for (int i = 0; i < j; i++) //the loop to get back all the info from the vector
{
cout << "ID :" << info[i].employeeID << " First Name :" << info[i].firstName << " Last Name :" <<
info[i].lastName << " Pay Rate :" << info[i].payRate << " Hours :"<< info[i].hours;
cout << endl;
//notice the info[i], which leads you to the employee you need and the ".hours" which leads to the hours info of that specific employee
}
system("pause");
return 0;
}
First, please read Tips and tricks for using C++ I/O (input/output). It might be helpful to understand C++ I/O.
Here are some comments on your code:
First
Use string instead of char.
struct Employee
{
int employeeID;
string firstName;
string lastName;
float payRate;
int hours;
};
Second
Use array of Employee object to store multiple employees.
Employee info[100];
Third
Use cin carefully depending data types. In your case, it would be something like this:
cout << "Enter in the Data for Employee number " << i + 1 << endl;
cout << setw(5) << "\n Please Enter The Employee ID Number: ";
cin >> info[i].employeeID;
cin.ignore(); //It is placed to ignore new line character.
cout << setw(5) << "\n Please Enter Employees First Name: ";
getline (cin, info[i].firstName);
cout << setw(5) << "\n Please Enter Employees Last Name: ";
getline (cin, info[i].lastName);
cout << setw(5) << "\n Please Enter Employees Pay Rate: ";
cin >> info[i].payRate;
cout << setw(5) << "\n Please Enter The Hours The Employee Worked: ";
cin >> info[i].hours;
Fourth
std::getline() can run into problems when used before std::cin >> var. So, std::cin.ignore() can be used in this case to solve the problem.
I hope it helps.
Here's my code:
#include <iostream>
#include <string>
using namespace std;
class Personal_Record {
public:
Personal_Record();
Personal_Record(string nam, string dob, string addr, int mobNum, string ema, string hob);
void Get_PersonalRecord();
void Display_PersonalRecord();
protected:
string name;
string dateOfBirth;
string address;
int mobileNumber;
string emailId;
string hobby;
};
Personal_Record::Personal_Record()
{
name = "";
dateOfBirth = "";
address = "";
hobby = "";
}
Personal_Record::Personal_Record(string nam, string dob, string addr, int mobNum, string ema, string hob)
{
name = nam;
dateOfBirth = dob;
address = addr;
mobileNumber = mobNum;
emailId = ema;
hobby = hob;
}
void Personal_Record::Get_PersonalRecord()
{
cout << endl << "Enter the name of the person: ";
cin >> name;
cout << endl << "Enter the date of birth: ";
cin >> dateOfBirth;
cout << endl << "Enter the address: ";
cin >> address;
cout << endl << "Enter the mobile number: ";
cin >> mobileNumber;
cout << endl << "Enter the e-mail id: ";
cin >> emailId;
cout << endl << "Enter any hobby the person has: ";
cin >> hobby;
}
void Personal_Record::Display_PersonalRecord()
{
cout << "Personal Record:" << endl << endl;
cout << "1.Name: " << name << endl;
cout << "2.Date Of Birth: " << dateOfBirth << endl;
cout << "3.Address: " << address << endl;
cout << "4.Mobile Number: " << mobileNumber << endl;
cout << "5.E-mail Id: " << emailId << endl;
cout << "6.Hobby" << hobby << endl;
}
class Professional_Record {
public:
Professional_Record();
Professional_Record(string nameOfCom, string pos, int xp);
void Get_Professional_Record();
void Display_Professional_Record();
protected:
string nameOfCompany;
string position;
int experienceInYears;
};
Professional_Record::Professional_Record()
{
nameOfCompany = "";
position = "";
experienceInYears = 0;
}
Professional_Record::Professional_Record(string nameOfCom, string pos, int xp)
{
nameOfCompany = nameOfCom;
position = pos;
experienceInYears = xp;
}
void Professional_Record::Get_Professional_Record()
{
cout << endl << "Enter name of the company: ";
cin >> nameOfCompany;
cout << endl << "Enter position in this company: ";
cin >> position;
cout << endl << "Enter number of years of experience: ";
cin >> experienceInYears;
}
void Professional_Record::Display_Professional_Record()
{
cout << "Professional Record: " << endl << endl;
cout << "Name of the Company: " << nameOfCompany << endl;
cout << "Position in this company: " << position << endl;
cout << "Number of years of experience: " << experienceInYears << endl;
}
class Academic_Record {
public:
Academic_Record();
Academic_Record(string nameOfCou, string nameOfCol, int passOut, float percent, string special);
void Get_Academic_Record();
void Display_Academic_Record();
protected:
string nameOfCourse;
string nameOfCollege;
int passOutYear;
float percentage;
string specialization;
};
Academic_Record::Academic_Record()
{
nameOfCourse = "";
nameOfCollege = "";
passOutYear = 0;
percentage = 0.0;
specialization = "";
}
Academic_Record::Academic_Record(string nameOfCou, string nameOfCol, int passOut, float percent, string special)
{
nameOfCourse = nameOfCou;
nameOfCollege = nameOfCol;
passOutYear = passOut;
percentage = percent;
specialization = special;
}
void Academic_Record::Get_Academic_Record()
{
cout << endl << "Enter the name of the course: ";
cin >> nameOfCourse;
cout << endl << "Enter the name of the college: ";
cin >> nameOfCollege;
cout << endl << "Enter year of passout: ";
cin >> passOutYear;
cout << endl << "Enter the percentage: ";
cin >> percentage;
cout << endl << "Enter the subject the person has specialized in: ";
cin >> specialization;
}
void Academic_Record::Display_Academic_Record()
{
cout << endl << "Academic Details:" << endl;
cout << "Name of the Course: " << nameOfCourse << endl;
cout << "Name of the College: " << nameOfCollege << endl;
cout << "Year of passout: " << passOutYear << endl;
cout << "Percentage acquired: " << percentage << endl;
cout << "The person has specialized in: " << specialization << endl;
}
class Bio_Data : public Personal_Record, public Professional_Record, public Academic_Record {
public:
void Display_BioData();
};
void Bio_Data::Display_BioData()
{
Display_PersonalRecord();
Display_Professional_Record();
Display_Academic_Record();
}
int main()
{
Bio_Data bd;
cout << "Enter Personal Information: " << endl << endl;
bd.Get_PersonalRecord();
cout << "Enter Professional Information: " << endl << endl;
bd.Get_Professional_Record();
cout << "Enter Academic Information: " << endl << endl;
bd.Get_Academic_Record();
bd.Display_BioData();
return 0;
}
Output of the following code:
Enter Personal Information:
Enter the name of the person: Suraj
Enter the date of birth: 02/04/1996
Enter the address: Varnam,A/38,Pune
Enter the mobile number: 8552004340
Enter the e-mail id:
Enter any hobby the person has: Enter Professional Information:
Enter name of the company:
Enter position in this company:
Enter number of years of experience: Enter Academic Information:
Enter the name of the course:
Enter the name of the college:
Enter year of passout:
Enter the percentage:
Enter the subject the person has specialized in: Personal Record:
1.Name: Suraj
2.Date Of Birth: 02/04/1996
3.Address: Varnam,A/38,Pune
4.Mobile Number: 2147483647
5.E-mail Id:
6.Hobby
Professional Record:
Name of the Company:
Position in this company:
Number of years of experience: 0
Academic Details:
Name of the Course:
Name of the College:
Year of passout: 0
Percentage acquired: 0
The person has specialized in:
The problem here is that after taking the mobile number it doesn't give me a prompt for email id or taking input for any other fields.It just gives me the output.And even in the output the mobile no. is turned into some garbage value not the original no. I entered.I really don't know whats going on.Can someone help me!
I have run the code on ubuntu and c++ shell online and they both seem to give me same results.
I don't know what this problem is called so don't get angry at me for asking this question!
You are storing the mobile number as an int, which has a max size of 32767 http://www.cplusplus.com/reference/climits/
8552004340 is too big!
Better to store it as a string.
So, I just had a question about my professors feedback on one of the programs we did. I didn't quite understand her feedback on what she meant by putting setters functions in the second constructor. Here is what she said:
Next time be sure to do the Reading and Preparation assigned before you attempt a lab. Read the assignment carefully.
The problem says the overloaded constructor (constructor #2) should call the setter functions.
The overloaded constructor (constructor #2) was not tested. Create an object with the overloaded constructor like so: Inventory itemTwo(666,3,.99);
Nice class, nice main program and coding style.
This was the problem:
Problem
And lastly, here's my code:
#include <iostream>
#include <iomanip>
using namespace std;
class Inventory
{
private:
int itemNumber; //Private Class Members
int quanity;
double cost;
public:
Inventory(); //Public Member Functions
Inventory(int i, int q, double c);
void setItemNumber(int);
void setQuanity(int);
void setCost(double);
int getItemNumber() const;
int getQuanity() const;
double getCost() const;
double getTotalCost() const;
};
int main()
{
int itemNum;
int qty;
double price;
Inventory itemOne; //Declares itemOne and itemTwo being an Inventory class objects
Inventory itemTwo;
/****************************************************************************/
cout << "Please Enter Data For Item One\n"; //Data entry for Item One
cout << "Enter item number: ";
cin >> itemNum;
while (itemNum < 0) //Safegaurds for data
{
cout << "Please enter a non-negative item number: ";
cin >> itemNum;
}
cout << "Enter quanity: ";
cin >> qty;
while (qty < 0)
{
cout << "Please enter a non-negative quanity number: ";
cin >> qty;
}
cout << "Enter price: ";
cin >> price;
while (price < 0)
{
cout << "Please enter a non-negative price: ";
cin >> price;
}
itemOne.setItemNumber(itemNum); //Passes All Data To Correct Functions
itemOne.setQuanity(qty);
itemOne.setCost(price);
cout << endl; //Formatting
/****************************************************************************/
cout << "Please Enter Data For Item Two\n"; //Data Entry for Item Two
cout << "Enter item number: ";
cin >> itemNum;
while (itemNum < 0)
{
cout << "Please enter a non-negative item number: ";
cin >> itemNum;
}
cout << "Enter quanity: ";
cin >> qty;
while (qty < 0)
{
cout << "Please enter a non-negative quanity number: ";
cin >> qty;
}
cout << "Enter price: ";
cin >> price;
while (price < 0)
{
cout << "Please enter a non-negative price: ";
cin >> price;
}
itemTwo.setItemNumber(itemNum); //Passes All Data To Correct Functions
itemTwo.setQuanity(qty);
itemTwo.setCost(price);
cout << endl; //Formatting
/****************************************************************************/
cout << fixed << showpoint << setprecision(2);
//All input displayed here
cout << "Here's the data you entered for item one:\n";
cout << "Item Number: " << " " << itemOne.getItemNumber() << endl;
cout << "Item Quanity: " << " " << itemOne.getQuanity() << endl;
cout << "Item Cost: " << " " << "$" << itemOne.getCost() << endl;
cout << "Item Total Cost: " << " " <<"$" << itemOne.getTotalCost() << endl << endl;
cout << "Here's the data you entered for item two:\n";
cout << "Item Number: " << " " << itemTwo.getItemNumber() << endl;
cout << "Item Quanity: " << " " << itemTwo.getQuanity() << endl;
cout << "Item Cost: " << " " << "$" << itemTwo.getCost() << endl;
cout << "Item Total Cost: " << " " <<"$" << itemTwo.getTotalCost() << endl;
return 0;
}
Inventory::Inventory() //Default Constructor
{
itemNumber = 0;
quanity = 0;
cost = 0;
}
Inventory::Inventory(int i, int q, double c) //Constructor #2
{
itemNumber = i;
quanity = q;
cost = c;
}
void Inventory::setItemNumber(int i) //Re-Evaluates For a Negative Number and
{ //Passes User's Entered Data to the Private class
if (i >= 0)
itemNumber = i;
else
itemNumber = 0;
}
void Inventory::setQuanity(int q) //Re-Evaluates For a Negative Number and
{ //Passes User's Entered Data to the Private class
if (q >= 0)
quanity = q;
else
quanity = 0;
}
void Inventory::setCost(double c) ////Re-Evaluates For a Negative Number and
{ //Passes User's Entered Data to the Private class
if (c >= 0)
cost = c;
else
cost = 0;
}
int Inventory::getItemNumber() const //All 'Getter' Functions to Display Object's Data
{ //Whilst Keeping Data Integrity With 'const'
return itemNumber;
}
int Inventory::getQuanity() const
{
return quanity;
}
double Inventory::getCost() const
{
return cost;
}
double Inventory::getTotalCost() const //Calculates Total Cost and Returns
{
return cost * quanity;
}
/*
-----------------------------------------------------
Please Enter Data For Item One
Enter item number: 1303
Enter quanity: 10
Enter price: 2.50
Please Enter Data For Item Two
Enter item number: 5676
Enter quanity: 54
Enter price: 5.65
Here's the data you entered for item one:
Item Number: 1303
Item Quanity: 10
Item Cost: $2.50
Item Total Cost: $25.00
Here's the data you entered for item two:
Item Number: 5676
Item Quanity: 54
Item Cost: $5.65
Item Total Cost: $305.10
-----------------------------------------------------
Please Enter Data For Item One
Enter item number: 7456
Enter quanity: 10
Enter price: 10.9
Please Enter Data For Item Two
Enter item number: 0293
Enter quanity: 5
Enter price: 109.23
Here's the data you entered for item one:
Item Number: 7456
Item Quanity: 10
Item Cost: $10.90
Item Total Cost: $109.00
Here's the data you entered for item two:
Item Number: 293
Item Quanity: 5
Item Cost: $109.23
Item Total Cost: $546.15
-----------------------------------------------------
*/
Your professor probably meant that you should call the setter functions in the constructor instead of setting the values directly:
Inventory::Inventory(int i, int q, double c) //Constructor #2
{
setItemNumber(i);
setQuantity(q);
setCost(c);
}
She's right. You are taking user input, therefore you must validate it with your setters, you created them for a reason.
Inventory::Inventory(int i, int q, double c) //Constructor #2
{
setItemNumber(i);
setQuantity(q);
setCost(c);
}