SYS-135� Introduction to Programming

 

Quiz 3 - 9/21/99

 

Name:� ��������� solutions������������� ������������������ ���������

 

1.� A void function can not have a parameter list. (2 points)

 

a.�� true����������� b.�� false

 

For both questions 2 and 3 assume the following main function:

 

#include <iostream.h>

#include <math.h>

float loopit ();

int main ()

{

����������� cout << �Program has started\n\n�;

����������� cout << �Function returns: �<< loopit ();

����������� return 0;

}

 

2.      What will be printed out when the program executes, assuming the following definition of loopit? (note: sqrt is the square root function in math.h) (4 points)

 

float loopit ()

{

����� cout << �loopit entered�;

����� return sqrt(16.0);

}

 

Answer:����������� Program has started��� ����������� ����������� ����������������������� ����������������������� ����������������������� ����������� ����������� __________________________________________________________________�����������������������������������������������������������������������������������������������������������������������������������

����������� ����������� Function Returns: loopit entered 4.0_____________________________________

����������������������� ����������������������� ����������������������� ����������������������� ����������������������� ����������������������� �����������

3.      What will be printed out when the program executes, assuming the following definition of loopit and assuming that you enter at the keyboard the number �7 ? (4 points)

 

float loopit ()

{

����� int var1;

����� cin var1;

����� return float(var1 * 2 + 3);

}

 

Answer:��������� Program has started� ����������� ����������������������� ����������������������� ����������� ����������� ����������� ����������� ����������� __________________________________________________________________���������������������������������������������������������������������������������������������������������������������������������

����������� ����������� Function Returns: loopit entered 11.0___________________________________