Cis 115
1. printTodaysDate();: printTodaysDate
is a function that accepts no parameters and returns no value.
Write a statement that calls printTodaysDate
.
2. void printDottedLine(){
cout<<" .... \n";
}: Write the definition of a function
printDottedLine
, which has no parameters and doesn't return anything.
The function prints a single line consisting of
5
periods (terminated by a new line character) .
3. void printTodaysDate();: Write a statement that declares a prototype for a func-
tion
printTodaysDate
, which has no parameters and doesn't return anything.
4. printErrorDescription(14);: printErrorDescription
is a function that accepts one
int
parameter and returns no value.
Write a statement that calls the function
printErrorDescription
, passing it the value
14
.
5. printLarger(sales1,sales2);: printLarger
is a function that accepts two
int
parameters and returns no value.
Two
int
variables,
sales1
and
sales2
, have already been declared and initialized.
Write a
statement
that calls
, Cis 115
printLarger
, passing it
sales1
and
sales2
.
6. void printLarger(int one,int two){
if(one>two)
cout<<one<<endl;
else
cout<<two<<endl;
}: Write the definition of a function
printLarger
, which has two
int
parameters and returns nothing. The function prints the larger value of the two
parameters on a single line by itself. (For purposes of this exercise, the "larger"
means "not the smaller".)
7. int add(int,int);: Write a statement that declares a prototype for a function named
add
which has two
int
parameters and returns an
int
.
8. eurasiaSales=add(asiaSales,euroSales);: add
is a function that accepts two
int
arguments and returns their sum.
Two
int
variables,
euroSales
and
asiaSales
, have already been declared and initialized. Another
int
variable,
eurasiaSales
, Cis 115
, has already been declared.
Write a statement that calls the
add
function to compute the sum of
euroSales
and
asiaSales
and store this value in
eurasiaSales
.
9. int oneLess(int amount){
return amount-1;
}: Write the definition of a function named
oneLess
, which receives an
int
argument and returns an
int
that is one less than the value of the argument. So if the argument's value is
7
, the function returns the value
6
. If the argument's value happens to be
44
, the functions returns the value
43
10. int half(int amount){
return amount/2;
}: Write the
definition
of a function named
half
, which receives an integer argument and returns an integer that is
half
the value of the parameter. (Use integer division!)
So if the argument's value is
7
, the function returns the value
, Cis 115
3
.
If the argument's value happens to be
44
, the functions returns the value
22
.
11. bool isPositive(int num){
if(num>0){
return true;
}
else{
return false;
}
}: Write the definition of a function named isPositive, that receives an integer argu-
ment and returns true if the argument is positive, and false otherwise.
So, if the argument's value is 7 or 803 or 141 the function returns true.
But if the argument's value is -22 or -57, or 0, the function returns false
12. int counter(){
static int x=0;
return x++;
}: Write the definition of a function named
counter
that receives no parameters and returns
0
the first time it is invoked, returns
1
the next time it is invoked, then
2
,
3
and so on.
13. double timeOnHighway(double mileEndingPoint,
double mileStartingPoint=0.0, double speed=55.0){
return (mileEndingPoint-mileStartingPoint)/speed;
}: Write the definition of a function named
1. printTodaysDate();: printTodaysDate
is a function that accepts no parameters and returns no value.
Write a statement that calls printTodaysDate
.
2. void printDottedLine(){
cout<<" .... \n";
}: Write the definition of a function
printDottedLine
, which has no parameters and doesn't return anything.
The function prints a single line consisting of
5
periods (terminated by a new line character) .
3. void printTodaysDate();: Write a statement that declares a prototype for a func-
tion
printTodaysDate
, which has no parameters and doesn't return anything.
4. printErrorDescription(14);: printErrorDescription
is a function that accepts one
int
parameter and returns no value.
Write a statement that calls the function
printErrorDescription
, passing it the value
14
.
5. printLarger(sales1,sales2);: printLarger
is a function that accepts two
int
parameters and returns no value.
Two
int
variables,
sales1
and
sales2
, have already been declared and initialized.
Write a
statement
that calls
, Cis 115
printLarger
, passing it
sales1
and
sales2
.
6. void printLarger(int one,int two){
if(one>two)
cout<<one<<endl;
else
cout<<two<<endl;
}: Write the definition of a function
printLarger
, which has two
int
parameters and returns nothing. The function prints the larger value of the two
parameters on a single line by itself. (For purposes of this exercise, the "larger"
means "not the smaller".)
7. int add(int,int);: Write a statement that declares a prototype for a function named
add
which has two
int
parameters and returns an
int
.
8. eurasiaSales=add(asiaSales,euroSales);: add
is a function that accepts two
int
arguments and returns their sum.
Two
int
variables,
euroSales
and
asiaSales
, have already been declared and initialized. Another
int
variable,
eurasiaSales
, Cis 115
, has already been declared.
Write a statement that calls the
add
function to compute the sum of
euroSales
and
asiaSales
and store this value in
eurasiaSales
.
9. int oneLess(int amount){
return amount-1;
}: Write the definition of a function named
oneLess
, which receives an
int
argument and returns an
int
that is one less than the value of the argument. So if the argument's value is
7
, the function returns the value
6
. If the argument's value happens to be
44
, the functions returns the value
43
10. int half(int amount){
return amount/2;
}: Write the
definition
of a function named
half
, which receives an integer argument and returns an integer that is
half
the value of the parameter. (Use integer division!)
So if the argument's value is
7
, the function returns the value
, Cis 115
3
.
If the argument's value happens to be
44
, the functions returns the value
22
.
11. bool isPositive(int num){
if(num>0){
return true;
}
else{
return false;
}
}: Write the definition of a function named isPositive, that receives an integer argu-
ment and returns true if the argument is positive, and false otherwise.
So, if the argument's value is 7 or 803 or 141 the function returns true.
But if the argument's value is -22 or -57, or 0, the function returns false
12. int counter(){
static int x=0;
return x++;
}: Write the definition of a function named
counter
that receives no parameters and returns
0
the first time it is invoked, returns
1
the next time it is invoked, then
2
,
3
and so on.
13. double timeOnHighway(double mileEndingPoint,
double mileStartingPoint=0.0, double speed=55.0){
return (mileEndingPoint-mileStartingPoint)/speed;
}: Write the definition of a function named