Class Implementation: i dont know how to go upon writing a program that tests the features of my customer class...please

i just started learning classes in programming. I am completely clueless on how to go upon writing a program that tests the features of my customer class. If i could get some help on how its suppose to look like and an example of how to start would help me tremendously as i really need help. Below is the customer class that the program will be based on...


#include <cstdlib>
#include <iostream>

class Customer
{
public:
Customer( string name, string address, string city, string state,
string zipcode);

void increase_limit(double amount);
string get_name() const;
string get_address() const;
string get_city() const;
string get_state() const;


private:
string name;
string address;
string city;
string state;
string zipcode;
double credit_limit;
}
using namespace std;



int main(int argc, char *argv[])
{
system("PAUSE");
return EXIT_SUCCESS;
}
Last edited on
Well, first, you need to decide what it is you actually want to test.

There doesn't seem to be any actual functionality in your class - all it has is:

- a constructor that takes some arguments and, presumably, initialises some of the data members
- some "get" access methods for those data members.
- an increase_limit method, that, presumably, changes the value of the credit_limit data member

So, really, the only thing you can test is that, when you call those "get" methods, they give you the same values as you originally supplied in the constructor.

As written, there's no way to test the increase_limit method, because you haven't supplied any way for a test program to obtain the value of it. Did you intend to write a "get" method for that too?

EDIT: And please use code tags when posting code, to make it readable:

http://www.cplusplus.com/articles/z13hAqkS/
Last edited on
yea i did intend to use a ''get'' methods for those.
how can i start testing for the get method mikeyboy... can you give a demonstration? ...and thanks for responding .
1) Use your constructor to create an object with known values for the various arguments

2) Use your get methods to retrieve the values of the data members

3) Check that the values you get back from those methods are the values they're supposed to be.
Hi @RichardBrains,
in addition to
@MikeyBoy's guideline
i have a little example
that may help to you!

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
//ExampleClass.cpp
//##

#include <iostream>
#include <string>

using namespace std;


class Cat{
        public:
                Cat(string Name,int Lives);
                string getName();
                int getLives();
        private:
                string name;
                int lives;
};//end class Cat

int main(){

//Testing Cat class
        Cat GrumpyCat("Tardar Sauce",9);
                cout<<"Cat name: "<<GrumpyCat.getName()<<endl;
                cout<<"Lives: "<<GrumpyCat.getLives()<<endl;

return 0; //indicates success
}//end of main

Cat::Cat(string Name,int Lives){
        name=Name;
        lives=Lives;
}//end class constructor

string Cat::getName(){
        return name;
}//end method getName

int Cat::getLives(){
        return lives;
}//end method getLives
./ExampleClass 
Cat name: Tardar Sauce
Lives: 9
thanks mikey boy and thanks eyenrique... you helped me soo much... its starting to hit me now!
You are welcome!
Topic archived. No new replies allowed.