roomtype

Please help with the roomtype function.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include<iostream>
#include<string>
#include"date.h"
using namespace std;

class Reservation
{

private:
  string name;
  Date checkin;
  Date checkout;
  double days;
  double price;
  

public:
    Reservation();
    //parameterized constructor
    Reservation(string, Date, Date, double, double);
    void setname(string);
    string getname();
    void setcheckin(int,int,int);
    void setcheckin(Date);
    double roomtype();
};
void Reservation::setname(string n)
{

    name=n;
    
}

string Reservation::getname()
{
    return name;
}

void Reservation::setcheckin(int m,int d, int y)
{
    checkin.setDate(m,d,y);
}

void Reservation::setcheckin(Date CI)
{
    checkin=CI;
}

double
double Reservation::roomtype()
{
   //type of room 
  //k= 120
  //d=99
}

int main()
{
    //Reservation ob();
    //string N;
    //cout<<"Welcome to our Reservation system";
    //cout<<"what is your name";
   // cin>>N;
 //   ob.setname(N);
    
}
Hello poohbear,

The answer is 42. https://www.youtube.com/watch?v=aboZctrHfK8

Without the "Date.h" file and a better understanding what you are wanting to do I am unable to guess at what needs fixed.

Andy
this is the date.h file

#include <iostream>
//header file
#include <iomanip>

using namespace std;

class Date

{
private:
int month, day, year;

public:
Date() //default constructor

{
month = 1;

day = 1;

year = 2000;
}

Date(int d, int m, int y) //constructor with the parameter

{
day = d;

month = m;

year = y;
}

bool setDate(int, int, int);

};


bool Date::setDate(int d, int m, int y) //function definitions

{
if (d > 30 )

{
cout << "Wrong date" << endl;

return false;
}

else

{
day = d;

if (m > 12)

{
cout << "Wrong month" << endl;

return false;
}

else

{
month = m;

year = y;

return true;
}
}
}
Hello poohbear,

Thank you. Now I have something to work with.

Still do not know what you need to do with "roomtype"?

Andy
Hello poohbear,

In the two files there are things that need fixed before you can proceed.

In "date.h":

Do not put includes like "iostream" and 'iomanip" in header files. What is in the ".cpp" file will cover this. More about this shortly. And never put using namespace std: in a header file. this is asking for real trouble. Take some time to read this: http://www.lonecpluspluscoder.com/2012/09/22/i-dont-want-to-see-another-using-namespace-xxx-in-a-header-file-ever-again/

Other than removing some blank lines there is nothing else wrong in the header file that would keep the program from compiling. The only thing I would have done differently is put the two ctors outside the class with the rest of the functions and I would put the class in a header file and the functions in a ".cpp" file.

"main" has more that needs fixed:

In the class, which should be in its own header file, you prototypd the two ctors, but never wrote the function for them. BTW it is best to put the class definition in a header file and the functions in a ".cpp" file, but what you have works.

On line 49 you have just the word "double" before the function "roomtype". This needs removed.

In main the line Reservation ob(); the () are not needed. This makes it a function call not a definition. Removing the () allowed line 64 to work.

Hints/Suggestions:

When naming a variable you should use something that describes what the variable is or used for. For instance "N"; When I see this I first think that it is defined as a constant because of the capital letter. Variable names are best started with a lower case letter. "name" is a much better choice than "N". Also if the variable name is comprised of two or more words using camel case is best as in "firstName". It is also accepted to use the underscore as in "first_Name". The way you write your variable names is your choice, but be consistent with what you choose.

When it comes to classes and structs these names are better started with a capital letter. As you did with "Reservation".

When a variable is defined as a constant this should be in all caps. This helps you to remember and let others know that it is a constant that can not be changed.

Now that the files are compile-able I will give it a test and see what happens.

Hope that helps,

Andy
Hello poohbear,

Once I created ctors for the "Reservation" class I could compile and run the program.

In "main" if you are planning on using the overloaded ctor of "Reservation" you will eventually need two "Date" objects to use with the overloaded ctor.

Next is your input. cin >> name; or "N" as you have it is known as formatted input. In this case "cin >>" will extract from the input buffer everything up to the first white space or new line whichever comes first.

Your two choices here create variables for "firstName" and "lastName", in which you could use: std::cin >> firstName >> lastName;, or use std::getline(std::cin, name);. This would depend on how you are going to use the name later in the program. It might work out better to have a first name and last name variables. This would be helpful later if you need to do a search.

After the years I have working with the display I tend to take the time to make it look more presentable. I offer this as one possibility of how you can do your opening screen.

1
2
3
std::cout<< '\n' << std::setw(20) << " " << "Welcome to our Reservation system\n";
std::cout<<"\n What is your name: ";
std::getline(std::cin, name);


What I would work on first is finishing the input in "main". The classes compile for now, but until you have information to put in them we do not know if they work properly.

Collecting the input you need will also help to decide how the "roomtype" function will work and if it needs any parameters, which I think it will, before you can work on "roomtype".

Note: the line return 0; at the end of main is not a strict requirement, but it is good form to put it in the program. Also it makes for a good break point in the IDE when debugging the program.

Work on getting the rest of the input in "main" and show me what you did.

Hope that helps,

Andy
Topic archived. No new replies allowed.