jeudi 31 mars 2016

How to allow a program to create new objects [on hold]

Thanks so much for taking the time to look at my question!

Right now I am working with classes and objects. I am trying to write a program that stores information about visitors to a hotel. A user will input the name of the visitor and some information about them. The program will then store that information in an object and be able to calculate how much to charge for the users stay.

The problem that I am running into is that I don't know how to let the program create new objects for the visitors. For example, if Sally came in I would like to create a new object for her within the program that could store her information.

I have looked at dynamic object creation and done a fair amount of Googling on the subject but can't seem to find any answers. Here is a simplified version of what I would like to do:

#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

class visitor {
public:
    string name;
    int age;
};

int main()
{
//a new person comes to the hotel, the person at the desk gives the program his/her name
//and age and it is put into a class so it can be used later.
}

If there is a better way to accomplish this I would love suggestions, I am but a fledgling programmer and it is very possible that I am approaching this incorrectly.

Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire