Question:
C++ question?
COD
2007-02-14 11:40:45 UTC
default constructor - set names to empty string and balance to zero
constructor that uses names only-default balance to zero
constructor with names and a beginning balnce

1. What are samples of how those would look like with these objects?

Declare these objects:
obj1 Sam donner with a balance of 2500
obj2 cheryl polk with no intial balnce
obj3 no name or balance

savings(); // obj 3
savings(string f, string l); //obj2
savings(string ff, string ll, float bal); // obj1
Three answers:
MartinPalermo
2007-02-14 12:01:16 UTC
Savings obj1("Sam", "Donner",2500);

Savings obj2("Cheryl","Polk");

Savings obj3;
KillingJoke
2007-02-14 20:00:58 UTC
//copy,compile and run



#include

#include



class savings

{

private:

char name[20];

int balance;

public:

savings()

{

strcpy(name,""); balance=0;

}

savings(char temp[])

{

strcpy(name,temp); balance=0;

}

savings(char temp[],int b)

{

strcpy(name,temp); balance=b;

}

~savings()

{

printf("\nName: %s Balance:%d",name,balance);

}

};

void main()

{

savings obj3,obj2("Cheryl polk"),obj1("Sam donner",2500);

}
bonesawosu
2007-02-14 19:46:00 UTC
look up "struct" because you could use that to get what you want.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...