float f();
float f(int& a, int b=10);
bool g(int,string);
int main()
{
int x=1,y=2,z=3;
float a,b,c,d;
bool flag;
a = f();
b = f(x);
c = f(y,z);
if (g(y,"comp11")) {
flag=g(z,"comp11");
}
cout << "The end!\n";
return 0;
}
float f() {
float d = 5.5;
return(d);
}
float f(int& a, int b) {
a+=10;
return(float(a)/b);
}
bool g(int mult,string s) {
static int big = 10;
if ((s == "comp11") && (big <= 10)) {
big *= mult;
mult +=1;
return true;
} else {
mult += 10;
return false;
}
}
Variable Values are:
y:
z:
m:
a:
b:
s:
c:
d:
string f(string & a, int b) {
char c;
string s;
s=a;
if (b>4)
c = 'R';
else
c = 'A' + b;
a = a + c;
return s;
}
int main() {
int x=1;
string s="CA",t;
t = f(s,x);
cout << x << " " << s << " " << t << endl;
}
The Program Prints:
int x=1;
int f(int a) {
x=a+3;
return x;
}
int main() {
int y;
y=f(x);
cout << x << " " << y << endl;
}
The Program Prints:
int x=1;
int f(int & a) {
a *= 2;
cout << "f():" << x << " " << a << endl;
return x;
}
int main() {
int y=5,z;
z=f(y);
cout << "main(): " << x << " " << y << " " << z << endl;
y=f(x);
cout << "main(): " << x << " " << y << " " << z << endl;
}
The Program Prints:
int f(int a, int b, int c=10) {
if ((a>b) && (a>c))
return a;
else
return(b+c);
}
int f(int a, float b=2.0) {
int c;
c = int(b)*3;
return(a+c);
}
int main() {
int x=3,y=1,R;
R = f(x,x,x);
cout << x << " " << y << " " << R << endl;
R = f(x);
cout << x << " " << y << " " << R << endl;
R = f(x,y);
cout << x << " " << y << " " << R << endl;
}
The Program Prints:
int f(int a) {
int d,m;
cout << "entering f(): " << a << endl;
if (a<10) {
d=m=a;
}
else {
d = a%10;
m = f(a/10);
if (d>m)
m = d;
}
cout << "exiting f(): " << a << " " << d << " " << m << endl;
return(m);
}
int main() {
int x=7913,y;
y = f(x);
cout << y << endl;
}
The Program Prints:
class Car {
public:
float gas;
Car() { gas=20;}
void drive(int a) { gas = gas - 0.5 * a; }
void fill() { gas = 20; }
float hours() { return(gas/0.5);}
};
int main() {
Car A,B;
cout << A.gas << endl;
A.drive(3);
A.drive(2);
cout << A.gas << endl;
B=A;
cout << B.hours() << endl;
B.fill();
cout << B.hours() << endl;
}
The Program Prints:
The header file:
The code file:
The cook function:
This document was generated using the LaTeX2HTML translator Version 98.1p1 release (March 2nd, 1998)
Copyright © 1993, 1994, 1995, 1996, 1997, Nikos Drakos, Computer Based Learning Unit, University of Leeds.
The command line arguments were:
latex2html -split 0 -no_navigation -no_images -dir TEMPHTML guide-x2.tex.
The translation was initiated by Roni Khardon on 2002-10-30