Calc 21

Páginas: 6 (1264 palabras) Publicado: 5 de marzo de 2013
1. Using the class Account and method main declared and defined below, create a derived class of Account called CheckingAccount. Define and declare only the constructors and operators needed in the CheckingAccount class so when the main method is executed it will produce the stated output. Assume you have access to the check method. Assume no incoming balance or interest rate should be anegative number. (19 pts)

class CheckingAccount:public Account{
private:
double interest;
public:
CheckingAccount(double bal,double rate);
friend ostream & operator << (ostream &out, const CheckingAccount &ck);
CheckingAccount & operator - (double value);
CheckingAccount & operator + (double value);
bool operator ==(const CheckingAccount &a) const;};
CheckingAccount::CheckingAccount(double bal, double rate):Account(bal){
Check(bal >=0,”Invalid Balance can not be negative”);
Check(rate >= 0, “Invalid interest rate can not be negative”);
interest = rate;
balance = balance * interest + balance;
}
CheckingAccount & CheckingAccount:: operator -(double value){
balance = balance - value;
return *this;
}CheckingAccount & CheckingAccount:: operator +(double value){
balance = balance + value;
return *this;
}

ostream & operator <<(ostream &out, const CheckingAccount &ck){
out << "Balance: " << ck.balance << endl;
out << "Interest: " << ck.interest << endl;
return out;
}
bool CheckingAccount::operator ==(const CheckingAccount &a)const{
return balance == a.balance && interest == a.interest;
}

2. Show the output for the following program, Assume all necessary includes are part of the program and there are no syntax errors or errors in the code below: (8 pts)

void method1(int *num, int & num);

int main(){
int *number = new int; //assume memory at 1010
int number2 = -105; // assumememory at 1020
*number = -80;
cout << number << " " << *number << endl;
cout << &number2 << " " << number2 << endl;
method1(number,number2);
cout << number << " " << *number << endl;
cout << &number2 << " " << number2 << endl;

void method1(int *num, int &num2){
num= &num2;
*num = 100;
num2 = 50;
}

1010 -80
1020 -105
1010 -80
1020 50

3. Show the output for the following program, Assume all necessary includes and a Makefile was used to compile the program below. Assume there are no syntax errors or errors in the code below: (14 pts)

void method2(StCalc* s,StCalc st[],StCalc* &s,StCalc &stC);

int main(){

StCalc a;//assume at memory 2010
StCalc sarr[2];
sarr[0] = a;
a.enter(100); //puts 100 on the screen of a
a.push().enter(3); //pushes 100 to stack and puts 3 on screen
a.push().add().pop(); //pushes 3 to stack adds 100+3 and puts 103 on screen
StCalc b; //assume at memory 2020
b + 600; // adds 600 to the screen of b
sarr[1] = b;
StCalc * s = new StCalc; //assume at memory 9010StCalc *st = new StCalc(a); //assume at memory 9020
s->enter(25); //puts 25 on the screen of s

cout << a << " " << b << endl;
cout << s << " " << *s << endl;
cout << st << " " << *st << endl;
cout << sarr[0]<< endl;
cout << sarr[1]<< endl;

method2(s,sarr,st,sarr[1]);cout << s << " " << *s << endl;
cout << st << " " << *st << endl;
cout << sarr[0]<< endl;
cout << sarr[1]<< endl;
}

void method2(StCalc* s,StCalc sarr[],StCalc* &st, StCalc &stC){
sarr[0].enter(s->getScreen()); //returns the screen value of s
sarr[1].clear(); //set the screen of sarr[1] to...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • que es calc
  • Calc
  • Calco
  • calc
  • Calc
  • Calc
  • EJERCICIOS CALC
  • Openoffice.org calc

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS