Can someone help please

This is a discussion on Can someone help please within the C++ Programming forums, part of the General Programming Boards category; I had to define a class named Customer that holds private fields for Customer ID number, last name, first name, ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    8

    Question Can someone help please

    I had to define a class named Customer that holds private fields for Customer ID number, last name, first name, and credit limit. There had to be four private functions that each set one of the four fields. Credit limits could not be over $10,000. Then a public function had to be included that would display the Customer's data. The main() program is where I had to declare a Customer, set the Customer's fields and display the results. I have completed this part sucessfully without error, at least it ran anyway.

    Code:
    #include<iostream.h>
    #include<conio.h>
    #include<string.h>
    class Customer
    {
    private:
       int customerIdNum;
       char lastName[15];
       char firstName[15];
       double creditLimit;
    public:
       void displayCustomerData();
       void setCustomerIdNum(int num);
       void setLastName(char name[]);
       void setFirstName(char name[]);
       void setCreditLimit(double CL);
    };
    //implementation section
    void Customer::displayCustomerData()
    {
       cout<<"Customer ID Number "<<customerIdNum<<"'s first name is "<<firstName<<endl;
       cout<<firstName<<"'s last name is "<<lastName<<endl;
       cout<<"The credit limit for this customer is $"<<creditLimit<<endl;
    }
    void Customer::setCreditLimit(double CL)
    {
       if( CL < 10000)
         creditLimit = CL;
       else
         creditLimit = 9999;
    }
    void Customer::setLastName(char name[])
    {
       strcpy(lastName, name);
    }
    void Customer::setFirstName(char name[])
    {
       strcpy(firstName, name);
    }
    void Customer::setCustomerIdNum(int num)
    {
       if ( customerIdNum < 10000)
         customerIdNum = num;
       else
         customerIdNum = 9999;
    }
    void main()
    {
       Customer aCustomer;
       aCustomer.setCreditLimit(7000);
       aCustomer.setLastName("Andrews");
       aCustomer.setFirstName("Melissa");
       aCustomer.setCustomerIdNum(754);
       aCustomer.displayCustomerData();
       getch();
    }
    Now I have to write a main() program that delcares an array of five Customers. I have to set all of the fields for each Customer, and display values for all five Customer objects. But I am so lost, I am not good with arrays at all



    Can anyone help?
    Last edited by crzy1; 02-09-2003 at 03:39 PM.

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    You aren't gonna get many answers if you don't use code tags.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    also don't use void main, if you want to know why, just do a search and type void main in search field, you will get numerous threads about it.

    but arrays, you could read the tutorial on this site, as well as other tutorials, they aren't that difficult.

    but:

    Code:
    Customer aCustomer[5];
    aCustomer[0].setCreditLimit(7000);
    hope that helps some.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21