calculating the bill of a customer according to the amount spent on shopping

Pages: 12
and then the setter function will be as follows??

void customer::setname(std::string i)
{
name= i;
}
is this all right??
closed account (o3hC5Di1)
Hi,

Yes, almost:

1
2
3
4
5
//need to use capital C in Customer
void Customer::set_name(std::string i)
{
    name= i;
}


You're understanding this, very well done :)

All the best,
NwN
yes i am getting something now :)
why is there need to write C in customer?

and what about getname() function??
this would be like as follows??
void customer::getname()
{
return name;
}
closed account (o3hC5Di1)
Hi there,

You need a captial C because your class is called Customer and not customer, that is called "case sensitivity".

Your getname function is nearly correct, only it isn't of type void, because it actually returns a value, a string in this case:

1
2
3
4
std::string Customer::getname()
{
    return name;
}


So as a basic rule, the function's type should always be that of the type it returns, when it returns nothing (like setname()), we use the type void.

Hope that makes sense to you.

All the best,
NwN
yeah it does :)
and how stupid the compiler is, it didn't mention the error:D
thanks that you told me

NOW it's almost 70% done
i am gonna right the friend function now
please tell me its declaration and how to right the prototype and how to call from the main()
i am waiting
i have written the defination as follows, is this correct way??

void calculate(customer *a,int i, float j, std::string k)
and i wrote this line in main()
calculate(&cptr,cus_name,cus_id,cus_spending);

this is right or not?
waiting
in doing friend function, i am having a serious trouble:(
Avast is terminating it each time i run it, there is no compilation error, but avast says there is some thing suspicious in it, and terminates it :(
i am just putting spending as a parameter
please help
dear brother:)
my code is almost 90% done now
and i am so glad to see it running
but there is a problem again, as you know i had to declare 3 constructors, you told me how to declare default constructor then parametrized and then the one which will take user inputs
i am facing the problem here, when i declared the 3rd object using new operator it calls the by default constructor first , i wrote it as follows
customer *cptr;
cptr= new customer();

how should i write it??
should i pass the parameters??
please guide me
i am so near to complete it
regards
closed account (o3hC5Di1)
Hi there,

Sorry for my late reply, I had to sign off yesterday as it was bedtime in this part of the world.

As to your questions:

Your friend function should only take an object as an argument, you will get the rest of the info out of that object:

1
2
3
4
5
6
7
8
9
10
float calculate(Customer * cu)
{
    float spent = cu->spent;
    //...
    return total;
}

Customer * mark;
mark = new Customer(34, 8000, "Mark");
cout << "Marks' total: " << calculate (mark);


Please note that your assignment says the following:


In the main() function, create three customer type objects by using new operator. Initialize first object with default constructor, second with parameterized and take input from user for third object (use setter functions to set third object’s values taken from the user).


It doesn't say you have to use 3 types of constructors, you need 2 types of constructors and another object of which the values are set using the setter functions:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Customer * anonymous;
Customer * mark;
Customer * generic;

//default constructor, id=0, spent=0, name=No name
anonymous = new Customer();  
//parameterized constructor, id=54, spent=8000, name=Mark
mark = new Customer(54, 8000, "Mark");

//default constructor, id=0, spent=0, name=No name
generic = new Customer();
generic->set_id(55);   // id=55
generic->set_spent(9000);  //spent=9000
generic->set_name("Tom"); //name=Tom 


Hope that helps, let me know how you get on :)

All the best,
NwN


Last edited on
yes dear
i did exactly the same, but there was some error that terminates it while running, but output is as it was required :)
bundle bundle of thanks for your deep concern and help
really thanks
may ALLAH bless you and give you it's reward
regards
closed account (o3hC5Di1)
Hi there,

Great, well done!
Thank you for your kind words and patience, most people just want us to solve it and not help them to do it themselves.

If you like you can post your code and I can have a look at why it would error.

Assalam-o-Alikum,
NwN
Assalam o alikum
yes there has been a logical error, that i was unable to understand, because i was running short of time and i had to submit it, so i stopped pondering over it :P
please tell me how can i upload my code here?
should i just copy paste here, or i can upload *.cpp file?
regards
dear NwN, i have uploaded another problem description. please guide me about that too
regards
Assalam o alikum
Topic archived. No new replies allowed.
Pages: 12