#include <iostream>
using namespace std;

class client
{
private:
    int choice;
    int age;
    int height;
    int weight;
    char *name;
public:
    void menu();
    void setStats();
    void task();
};
//========================================================
void client::menu()
{
    cout<< "MENU \n";
    cout<< "1. enter data \n";
    cout<< "2. view data \n";
    cout<< "3. quit \n";
    int chc;
    cin>> chc;
    choice=chc;
}
//========================================================
void client::task()
{
    switch(choice)
    {
        case(1): setStats();
    }
}
//========================================================
void client::setStats()
{
    int i,j,k;
    char *n;
    cout<< "name- "; cin>> n;
    cout<< "age- "; cin>> i;
    cout<< "height-"; cin>> j;
    cout<< "weight-"; cin>> k;

name=n; age=i; height=j; weight=k;
}
//========================================================
int main()
{
    client clients;
    clients.menu();
    clients.task();
}

posted this one for easier understanding of my question, no need to look deeper into the code.
the question is, how to make multiple output. say i got clients named a,b,c.
how do i enter the data of those 3 and then print it all out? please keep it as simple as possible :)

Recommended Answers

All 3 Replies

>please keep it as simple as possible

client a, b, c;

a.setStats();
b.setStats();
c.setStats();

Of course, this is assuming your client class wasn't broken, which it is. But since people tend to rail on me for answering questions that weren't asked, I won't go into detail.

oh but do go into detail :)
also, i dont know what was on my mind when i was writing the original post but i forgot to mention that after client a adding more clients is optional, if one selects new data it'll add, if he wont-it wont. also its not limited to 3 clients, its rather as many as user wishes. what im saying is that this should be done somewhere within a class...or something :|

You should probably have at least a default constructor in the public section of your class (and a destructor wouldn't hurt either). You are going to run into trouble in line 40 in the code you posted. You are trying to store data in a char*, but you have not set aside any data for the char*. You need to set aside space to store the data from the cin command.

I'm not sure what you are asking as far as what should be in the class and what shouldn't, but I would put Narue's code from post 2 (or whatever code you end up with that declares and creates a variable of type "client") outside of the client class (in main, say, or somewhere else outside of the client class). If you want to have the ability to have as many clients as the user may desire, you could use an array or a vector or a linked list or something like that. You aren't stuck with an exact, invariable number of clients.

To display the information, I would probably add a class function called "DisplayClient" and make it a public member function of your client class. That function would have the cout statements.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.