Hot Dog Stand static function issue - c++

I need this program to create a new HotDogStand object that is able to track how many hot dogs are sold by each stand individually and all together, and I cannot figure out how to make my static method work to find the total number of hot dogs sold between all stands. Can someone point me in the right direction please?
#include <iostream>
using namespace std;
class HotDogStand
{
public:
HotDogStand(int id, int hds);
void justSold();
int getNumSold();
int getID();
int getTotalSold();
private:
int idNum;
int hotDogsSold;
static int totalSold;
};
HotDogStand::HotDogStand(int id, int hds)
{
idNum = id;
hotDogsSold = hds;
return;
}
void HotDogStand::justSold()
{
hotDogsSold++;
return;
}
int HotDogStand::getNumSold()
{
return hotDogsSold;
}
int HotDogStand::getID()
{
return idNum;
}
int HotDogStand::getTotalSold()
{
totalSold = 0;
totalSold += hotDogsSold;
}
int main()
{
HotDogStand s1(1, 0), s2(2, 0), s3(3, 0);
s1.justSold();
s2.justSold();
s1.justSold();
cout << "Stand " << s1.getID() << " sold " << s1.getNumSold() << "." << endl;
cout << "Stand " << s2.getID() << " sold " << s2.getNumSold() << "." << endl;
cout << "Stand " << s3.getID() << " sold " << s3.getNumSold() << "." << endl;
cout << "Total sold = " << s1.getTotalSold() << endl;
cout << endl;
s3.justSold();
s1.justSold();
cout << "Stand " << s1.getID() << " sold " << s1.getNumSold() << "." << endl;
cout << "Stand " << s2.getID() << " sold " << s2.getNumSold() << "." << endl;
cout << "Stand " << s3.getID() << " sold " << s3.getNumSold() << "." << endl;
cout << "Total sold = " << s1.getTotalSold() << endl;
}

Globally (outside of the class), you have to define the static variable:
int HotDogStand::totalSold = 0;
Change
void HotDogStand::justSold()
{
hotDogsSold++;
totalSold++; // increment here
return;
}
And
int HotDogStand::getTotalSold()
{
return totalSold; // just return value
}

Related

Compiler error - is private within this context - Line 31

#include<iostream>
#include<string>
using namespace std;
class Item{
private:
string type;
string abbrv;
string uID;
int aircraft;
double weight;
string destination;
public:
void print(){
cout << "ULD: " << type << endl;
cout << "Abbreviation: " << abbrv << endl;
cout << "ULD-ID: " << uID << endl;
cout << "Aircraft: " << aircraft << endl;
cout << "Weight: " << weight << " Kilograms" << endl;
cout << "Destination: " << destination << endl;
}
friend void kilotopound(Item);
};
void kilotopound(Item I){
cout << "Weight in Pounds: " << I.weight * 2.2 << " LBS " << endl;
}
int main(){
Item I;
I.type = "Container";
I.uID = "AYK68943IB";
I.abbrv = "AYK";
I.aircraft = 737;
I.weight = 1654;
I.destination = "PDX";
I.print();
kilotopound(I);
return 0;
}
Starting on line 31 I'm getting the error 'std::__cxxll::string Item::type' is private within this context
I'm basically trying to make the data private from this code
class Item{
public:
string type;
string abbrv;
string uID;
int aircraft;
double weight;
string destination;
void print(){
cout << "ULD: " << type << endl;
cout << "Abbreviation: " << abbrv << endl;
cout << "ULD-ID: " << uID << endl;
cout << "Aircraft: " << aircraft << endl;
cout << "Weight: " << weight << " Kilograms" << endl;
cout << "Destination: " << destination << endl;
}
friend void kilotopound(Item);
};
void kilotopound(Item I){
cout << "Weight in Pounds: " << I.weight * 2.2 << " LBS " << endl;
}
int main(){
Item I;
I.type = "Container";
I.uID = "AYK68943IB";
I.abbrv = "AYK";
I.aircraft = 737;
I.weight = 1654;
I.destination = "PDX";
I.print();
kilotopound(I);
return 0;
}
Any help would be greatly appreciated, I'm just sort of lost on how I can resolve the error. Thanks!
Also I need to be able to copy and output the copied data once again if anyone can help with that as well, with private data too. Thanks again!
#include<iostream>
#include<string>
using namespace std;
class Item{
private:
string type;
string abbrv;
string uID;
int aircraft;
double weight;
string destination;
public:
Item(string t, string a, string u, int aC, double w, string d){
type = t;
abbrv = a;
uID = u;
aircraft = aC;
weight = w;
destination = d;
}
void print() {
cout << "ULD: " << type << endl;
cout << "Abbreviation: " << abbrv << endl;
cout << "ULD-ID: " << uID << endl;
cout << "Aircraft: " << aircraft << endl;
cout << "Weight: " << weight << " Kilograms" << endl;
cout << "Destination: " << destination << endl;
}
friend void kilotopound(Item);
};
void kilotopound(Item I){
cout << "Weight in Pounds: " << I.weight * 2.2 << " LBS " << endl;
}
int main(){
Item I ("Container", "AYK68943IB", "AYK", 737, 1654, "PDX");
I.print();
kilotopound(I);
return 0;
}

C++ proper usage of ostream inside a class and passing arguments?

I've recently started learning c++ and for the life of me, I can't seem to get the syntax of using ostream in a class and what arguments should I pass. Here's the code:
This is the class in question:
#include <iostream>
#include <string>
using namespace std;
class Pokemon{
friend ostream& operator<<(ostream&, Pokemon);
public:
string name, level, cp;
Pokemon(string x="Pikachu", string y="5", string z="1000"){
name = x;
level = y;
cp = z;
}
Pokemon name(){
return this->name;
}
Pokemon level(){
return this->level;
}
Pokemon cp(){
return this->cp;
}
Pokemon display_stats(){
cout << this-> name << "stats are:" << endl;
cout << " " << "Attack: 2716.05" << endl;
cout << " " << "Defence: 1629.63" << endl;
cout << " " << "HP: 1086.42" << endl;
}
};
template<typename TYPE> //i dont understand this and the things i've written down here are only based on samples i've seen
ostream& operator<<(ostream& os, Pokemon & c){
os << "The level of " << c.name << " is" << c.level << " with cp of " << c.cp;
}
As you could see, I already tried constructing the ostream thing but I don't really understand how it works. This is my main function:
int main()
{
Pokemon a, b, c, d;
a = Pokemon();
b = Pokemon("Weezing");
c = Pokemon("Nidoking", 100);
d = Pokemon("Mewtwo", 50, 5432.1);
cout << a << endl;
cout << b << endl;
cout << c << endl;
cout << d << endl;
cout << "Jessie: You are no match to me! Go " << b.name << "!" << endl;
cout << "Gary: Go lvl " << c.level << " " << c.name << "! Crush them" << endl;
cout << "Ash: " << a.name << " can do it even thouh he is only level " << a.level << endl;
cout << "Jessie: Hahaha! My " << b.name << " CP is " << b.cp << endl;
cout << "Gary: "<< c.name << " CP is " << c.cp << endl;
cout << "Ash: " << a.name << " CP is " << a.cp << endl;
cout << "Giovanni: Behold " << d.name << " is here." << endl;
d.display_stats();
return 0;
}
I'm getting errors of:
no instance of constructor "Pokemon::Pokemon" matches the argument list -- argument types are: (const char [9], int) //on line c = Pokemon("Nidoking", 100);
no instance of constructor "Pokemon::Pokemon" matches the argument list -- argument types are: (const char [7], int, double) //on line d = Pokemon("Mewtwo", 50, 5432.1);
All of your Pokemon class methods are returning the wrong type. And your main() is not calling any of the methods correctly at all.
Change your Pokemon class to look more like this:
#include <iostream>
#include <string>
using namespace std;
class Pokemon {
private:
string m_name;
int m_level;
double m_cp;
friend ostream& operator<<(ostream&, const Pokemon&);
public:
Pokemon(string x="Pikachu", int y=5, double z=1000) {
m_name = x;
m_level = y;
m_cp = z;
}
string name() const {
return m_name;
}
int level() const {
return m_level;
}
double cp() const {
return m_cp;
}
void display_stats() const {
cout << m_name << " stats are:" << endl;
cout << " " << "Attack: 2716.05" << endl;
cout << " " << "Defense: 1629.63" << endl;
cout << " " << "HP: 1086.42" << endl;
}
};
ostream& operator<<(ostream& os, const Pokemon &c) {
os << "The level of " << c.m_name << " is " << c.m_level << " with cp of " << c.m_cp;
return os;
}
And then change main() to look more like this:
int main()
{
Pokemon a;
Pokemon b("Weezing");
Pokemon c("Nidoking", 100);
Pokemon d("Mewtwo", 50, 5432.1);
cout << a << endl;
cout << b << endl;
cout << c << endl;
cout << d << endl;
cout << "Jessie: You are no match to me! Go " << b.name() << "!" << endl;
cout << "Gary: Go lvl " << c.level() << " " << c.name() << "! Crush them" << endl;
cout << "Ash: " << a.name() << " can do it even though he is only level " << a.level() << endl;
cout << "Jessie: Hahaha! My " << b.name() << " CP is " << b.cp() << endl;
cout << "Gary: " << c.name() << " CP is " << c.cp() << endl;
cout << "Ash: " << a.name() << " CP is " << a.cp() << endl;
cout << "Giovanni: Behold " << d.name() << " is here." << endl;
d.display_stats();
return 0;
}
Live Demo

My code works but the setters don't create new objects so I get the wrong results

So whenever I post the following code I get the wrong responses,
The class member variables do get updated with my setters, but for some reason the final cost is incorrect. I am not allowed to change the main.cpp codes
I am thinking that it might be something with the setters but I can't figure out how to force the setters to invoke the constructor so the setTotalCost() can get invoked
main.cpp
#include <iostream>
#include <iomanip>
#include "Inventory.h"
using namespace std;
int main()
{
cout << fixed
<< showpoint
<< setprecision(2);
// Demonstrate the default constructor
Inventory stockItem1;
cout << "\nDemonstrating the default constructor...\n";
cout << "Item number: " << stockItem1.getItemNumber() << endl;
cout << "Quantity : " << stockItem1.getQuantity() << endl;
cout << "Cost : " << stockItem1.getCost() << endl;
cout << "Total Cost : " << stockItem1.getTotalCost() << endl;
// Now demonstrate the overloaded constructor
Inventory stockItem2(124, 12, 84.95);
cout << "\nDemonstrating the overloaded constructor...\n";
cout << "Item number: " << stockItem2.getItemNumber() << endl;
cout << "Quantity : " << stockItem2.getQuantity() << endl;
cout << "Cost : " << stockItem2.getCost() << endl;
cout << "Total Cost : " << stockItem2.getTotalCost() << endl;
// Now demonstrate the member "set" functions
stockItem2.setItemNumber(243);
stockItem2.setQuantity(50);
stockItem2.setCost(9.50);
cout << "\nDemonstrating the \"set\" functions...\n";
cout << "Item number: " << stockItem2.getItemNumber() << endl;
cout << "Quantity : " << stockItem2.getQuantity() << endl;
cout << "Cost : " << stockItem2.getCost() << endl;
cout << "Total Cost : " << stockItem2.getTotalCost() << endl;
// Now demonstrate the input validation functions
cout << "\nDemonstrating the input validation functions...\n";
stockItem2.setItemNumber(-1);
stockItem2.setQuantity(-1);
stockItem2.setCost(-1);
cout << "\nItem number: " << stockItem2.getItemNumber() << endl;
cout << "Quantity : " << stockItem2.getQuantity() << endl;
cout << "Cost : " << stockItem2.getCost() << endl;
cout << "Total Cost : " << stockItem2.getTotalCost() << endl;
return 0;
}
Inventory.h
//Header File
#include<iostream>
#ifndef INVENTORY_H
#define INVENTORY_H
class Inventory
{
private:
int itemNumber;
int quantity;
double cost;
double totalCost;
public:
// default constructor, setting all values to 0
Inventory();
Inventory(int, int, double);
void setItemNumber(int );
void setQuantity(int );
void setCost(double );
void setTotalCost();
int getItemNumber();
int getQuantity();
double getCost();
double getTotalCost();
};
#endif //PROGRAM6_INVENTORY_H
Inventory.cpp
#include <iostream>
#include "Inventory.h"
using namespace std;
Inventory :: Inventory()
{
itemNumber = 0;
quantity = 0;
cost = 0;
totalCost = 0;
}
Inventory ::Inventory(int itemNumber, int quantity, double cost)
{
setItemNumber(itemNumber);
setQuantity(quantity);
setCost(cost);
setTotalCost();
}
void Inventory ::setItemNumber(int theItemNumber)
{
if (theItemNumber > 0)
{
itemNumber = theItemNumber;
}
else
{
cout << "You entered " << theItemNumber << " as your item number. Only positive numbers are accepted"<<endl;
}
}
void Inventory ::setQuantity(int quantityOfItems)
{
cout << "Setting quantity to " << quantityOfItems << endl;
if (quantityOfItems > 0)
{
quantity = quantityOfItems;
}
else
{
cout << "You entered " << quantityOfItems << " as your item quantity. Only positive numbers are accepted"
<< endl;
}
}
void Inventory ::setCost(double costOfItems)
{
if (costOfItems > 0)
{
cost = costOfItems;
}
else
{
cout << "You entered " << costOfItems << " item cost. Only positive numbers are accepted" << endl;
exit(0);
}
}
void Inventory ::setTotalCost()
{
int itemCount = getQuantity();
double itemCost = getCost();
totalCost = itemCost * itemCount;
}
int Inventory ::getItemNumber()
{
return itemNumber;
}
int Inventory ::getQuantity()
{
return quantity;
}
double Inventory ::getCost()
{
return cost;
}
double Inventory ::getTotalCost()
{
return totalCost;
}
I get the following output:
Demonstrating the default constructor...
Item number: 0
Quantity : 0
Cost : 0.00
Total Cost : 0.00
Demonstrating the overloaded constructor...
Item number: 124
Quantity : 12
Cost : 84.95
Total Cost : 1019.40
Demonstrating the "set" functions...
Item number: 243
Quantity : 50
Cost : 9.50
Total Cost : 1019.40
Demonstrating the input validation functions...
You entered -1 as your item number. Only positive numbers are accepted
You entered -1 as your item quantity. Only positive numbers are accepted
You entered -1.00 item cost. Only positive numbers are accepted
Process finished with exit code 0
for what I see, you do not call setTotalCost() after change the other variable. It will not happen automatically.
Hope it helps.
So, you need to make it so getTotalCost() returns the correct value without a setTotalCost() being explicitly called after the inputs to that value are updated. There are two ways that you can do this - you can have the setters for the inputs call that setter, or you can not store the value totalCost at all and recalculate every time you call getTotalCost().

C++ Output Errors (New Issues added)

My program seems to only be running through 2 courses then it ceases and displays the second course 3 times.
I am stumped and pulling my hair out, any suggestions would help a lot.
I also apologize in advance for the long post but I feel all parts are needed to identify the problem.
Here's the current output:
Current output
My expected output is:
Title: Title Course ID: 12345 Session: 54321 Units: 1.2
Here's where the error is:
#include <fstream>
#include <string>
#include <iomanip>
#include "Course.h"
using namespace std;
int main()
{
string title;
double units;
int course;
int session;
cout << "Enter the title of a course:";
cin >> title;
cout << "Enter the course ID number";
cin >> course;
cout << "Enter the number of units for the course";
cin >> units;
cout << "Enter the session number for the course";
cin >> session;
Courses Class_1(title, session, units, course);
cout << endl << "Class title: " << Class_1.getTitle() << endl <<
"title: " << setw(5) << Class_1.getTitle() <<
setw(5) << "course ID: " << setw(5) << Class_1.getCourseID() <<
setw(5) << "Session number: " << setw(5) << Class_1.getSessionNumber() <<
setw(5) << "Units: " << setw(5) << Class_1.getNumOfUnits() << endl;
cout << "Enter the title of a course:";
cin >> title;
cout << "Enter the course ID number";
cin >> course;
cout << "Enter the number of units for the course";
cin >> units;
cout << "Enter the session number for the course";
cin >> session;
Courses Class_2;
Class_2.setTitle(title);
Class_2.setCourseID(course);
Class_2.setSessionNumber(session);
Class_2.setNumOfUnits(units);
cout << endl << "Class title: " << setw(5) << Class_2.getTitle() << endl <<
"title: " << setw(5) << Class_2.getTitle() <<
setw(5) << "course ID: " << setw(5) << Class_2.getCourseID() <<
setw(5) << "Session number: " << setw(5) << Class_2.getSessionNumber() <<
setw(5) << "Units: " << setw(5) << Class_2.getNumOfUnits() << endl;
cout << Class_1.getTitle() << endl;
// -----------------------------------------------------------------
Courses Class_3;
Class_3.setTitle(title);
Class_3.setCourseID(course);
Class_3.setSessionNumber(session);
Class_3.setNumOfUnits(units);
cout << endl << "Class title: " << setw(5) << Class_3.getTitle() << endl <<
"title: " << setw(5) << Class_3.getTitle() <<
setw(5) << "course ID: " << setw(5) << setw(5) << Class_3.getCourseID() <<
setw(5) << "Session number: " << setw(5) << setw(5) << Class_3.getSessionNumber() <<
setw(5) << "Units: " << setw(5) << Class_3.getNumOfUnits() << endl;
cout << Class_2.getTitle() << endl;
// -----------------------------------------------------------------------
Courses Class_4;
Class_4.setTitle(title);
Class_4.setCourseID(course);
Class_4.setSessionNumber(session);
Class_4.setNumOfUnits(units);
cout << endl << "Class title: " << setw(5) << Class_4.getTitle() << endl <<
"title: " << setw(5) << Class_4.getTitle() <<
setw(5) << "course ID: " << setw(5) << Class_4.getCourseID() <<
setw(5) << "Session number: " << setw(5) << Class_4.getSessionNumber() <<
setw(5) << "Units: " << setw(5) << Class_4.getNumOfUnits() << endl;
cout << Class_3.getTitle() << endl;
system("pause");
return 0;
}
Here's the header:
#pragma once
#include <iostream>
#include <string>
using namespace std;
#ifndef COURSES_H
#define COURSES_H
class Courses
{
public:
// Default Constructor
Courses();
// Ovverload Constructor
Courses(string title, int course, int session, double units);
// Destructor
~Courses();
int getCourseID() const;
// Gets the course ID.
int getSessionNumber() const;
// Gets the session number.
double getNumOfUnits() const;
// Gets the number of units.
string getTitle() const;
// Gets the title of a course.
// --------------------------------
void setCourseID(int);
// Sets the ID number of a course.
void setSessionNumber(int);
// Sets the session number of a course.
void setNumOfUnits(double);
// Sets the number of units of a course.
void setTitle(string);
// Sets the title of a course.
private:
// Member Variables
string newTitle;
int newCourseID;
int newSessionNumber;
double newNumOfUnits;
};
#endif // !COURSE_H
And here's Course.cpp
#include "Course.h"
Courses::Courses()
{
newCourseID = 0;
newSessionNumber = 0;
newNumOfUnits = 0.0;
}
Courses::Courses(string title, int course, int session, double units)
{
newTitle = title;
newCourseID = course;
newSessionNumber = session;
newNumOfUnits = units;
}
Courses::~Courses()
{
}
string Courses::getTitle() const
{
return newTitle;
}
int Courses::getCourseID() const
{
return newCourseID;
}
double Courses::getNumOfUnits() const
{
return newNumOfUnits;
}
int Courses::getSessionNumber() const
{
return newSessionNumber;
}
// -------------------------------------
void Courses::setTitle(string title)
{
newTitle = title;
}
void Courses::setCourseID(int course)
{
newCourseID = course;
}
void Courses::setNumOfUnits(double units)
{
newNumOfUnits = units;
}
void Courses::setSessionNumber(int session)
{
newSessionNumber = session;
}
Your constructor is declared as Courses(string title, int course, int session, double units)
but you're calling it as Courses Class_1(title, session, units, course);
just switch around the variables and it should be fine
Courses Class_1(title,course,session,units);

Why Do I have an '=' sign output and 2 smiley faces instead of the correct output? C++

this is an update to show chages, details below.
here is a link to snap shot of output
https://dl.dropboxusercontent.com/u/34875891/wrongoutput.PNG
#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
using namespace std;
//create HotelRoom class
class HotelRoom
{
private:
char* ptr_guest;
char room_number[3];
int room_capacity;
int occupancy_status;
double daily_rate;
public:
HotelRoom(char roomNumber[], int roomCapacity, double roomRate, char* ptr_name, int occupancyStatus);
~HotelRoom();
void Display_Number();
void Display_Guest();
int Get_Capacity();
int Get_Status();
double Get_Rate();
int Change_Status(int);
double Change_Rate(double);
};
HotelRoom::HotelRoom(char roomNumber[], int roomCapacity, double roomRate, char* ptr_name, int occupancyStatus)
{
strcpy(room_number, roomNumber);
room_capacity = roomCapacity;
daily_rate = roomRate;
ptr_guest = new char[strlen(ptr_name) + 1];
strcpy(ptr_guest, ptr_name);
occupancy_status = occupancyStatus;
}
HotelRoom::~HotelRoom()
{
cout << endl;
cout << "Destructor Executed";
cout << endl;
delete [] ptr_guest;
}
void HotelRoom::Display_Guest()
{
char* temp = ptr_guest;
while(*temp != '\0')
cout << *temp++;
}
void HotelRoom::Display_Number()
{
cout << room_number;
}
int HotelRoom::Get_Capacity()
{
return room_capacity;
}
int HotelRoom::Get_Status()
{
return occupancy_status;
}
double HotelRoom::Get_Rate()
{
return daily_rate;
}
int HotelRoom::Change_Status(int roomStatus)
{
if(roomStatus <= room_capacity )
{
occupancy_status = roomStatus;
return occupancy_status;
}
else
occupancy_status = -1;
}
double HotelRoom::Change_Rate(double newRate)
{
daily_rate = newRate;
return daily_rate;
}
int main()
{
cout << setprecision(2)
<< setiosflags(ios::fixed)
<< setiosflags(ios::showpoint);
//Declare variables to hold data
char roomNumber[3] = {'1','3','\0'};
char guestName[20];
double roomRate = 89.00;
int roomCapacity = 4;
int occupancyStatus = 0;
int status;
int checkOut;
int newCustomer;
//Ask for user input
cout << "What is the guest's name: ";
cin.getline(guestName, 20);
cout << endl;
cout << "How many guests will be staying in the room: ";
cin >> status;
HotelRoom HotelRoom1(roomNumber, roomCapacity, roomRate, guestName, status);
//Display Rooom information
cout << endl;
cout << endl;
if(HotelRoom1.Change_Status(status))
{
cout << endl;
cout << "Guest's Name: ";
HotelRoom1.Display_Guest();
cout << endl;
cout << endl;
cout << "The capacity of this room is " << HotelRoom1.Get_Capacity() << endl;
cout << endl;
cout << "There are " << HotelRoom1.Get_Status() << " guests staying in the room";
}
cout << endl;
cout << endl;
cout << "Your room number is " << HotelRoom1.Display_Number();
cout << endl;
cout << endl;
cout << "The rate for this room is " << HotelRoom1.Get_Rate();
cout << endl;
cout << endl;
//chech this guest out?
cout << "Check this guest out? ('1 = yes' '0' = no) ";
cin >> checkOut;
switch(checkOut)
{
case 1:
HotelRoom1.Change_Status(0);
for(int i = 0; i < 3; ++i )
{
cout << endl;
}
cout << "You have checked out of room number " << HotelRoom1.Display_Number();
cout << endl;
cout << endl;
cout << "The capacity of this room is " << HotelRoom1.Get_Capacity();
cout << endl;
cout << endl;
cout << "There are currently " << HotelRoom1.Get_Status() << " occupants";
cout << endl;
cout << endl;
cout << "The rate of this room was " << HotelRoom1.Get_Rate();
break;
}
//check in new guest?
cout << endl;
cout << endl;
cout << "Check in new guest? ('1 = yes' '0' = no) ";
cin >> newCustomer;
for(int i = 0; i < 3; ++i )
{
cout << endl;
}
switch (newCustomer)
{
case 1:
HotelRoom HotelRoom2(roomNumber, roomCapacity, roomRate, guestName, status);
HotelRoom1.Change_Rate(175.00); //Change rate of room
cout << endl;
cout << "What is the guest's name: ";
cin.getline(guestName, 20);
cout << endl;
cout << "How many guests will be staying in the room: ";
cin >> status;
cout << endl;
cout << endl;
//Display new guest information
if(HotelRoom1.Change_Status(status))
{
cout << endl;
cout << endl;
cout << "The capacity of this room is " << HotelRoom1.Get_Capacity() << endl;
cout << endl;
cout << "There are " << HotelRoom1.Get_Status() << " guests staying in the room";
}
cout << endl;
cout << endl;
cout << "Your room number is " << HotelRoom1.Display_Number();
cout << endl;
cout << endl;
cout << "The rate for this room is " << HotelRoom1.Get_Rate();
cout << endl;
cout << endl;
break;
}
cout << endl;
system("PAUSE");
return 0;
}
this is an update to show chages, details below.
here is a link to snap shot of output
https://dl.dropboxusercontent.com/u/34875891/wrongoutput.PNG
char HotelRoom::Display_Guest()
{
cout << ptr_guest;
}
string HotelRoom::Display_Number()
{
cout << room_number;
}
int HotelRoom::Change_Status(int roomStatus)
{
if(roomStatus <= room_capacity )
{
occupancy_status = roomStatus;
return occupancy_status;
}
else
occupancy_status = -1;
}
These functions claim to be returning values. The first two are not, the last is not under certain conditons. Calling the first two is undefined behavior. Calling Change_Status with roomStatus > room_capacity is also undefined behavior.
There may be other problems with the code, but the elephant in the room is the undefined behavior. Any other debugging while you have undefined behavior is theoretically a waste of time.