SYCS-135�
Introduction to Programming
Quiz 4 - 10/7/99
Name:� ����������������������������������������������������������������������
For both questions 1 and 2 assume
the following main function:
#include <iostream.h>
float loopit ();
void main ()
{
����� int i1 = 3;
����� float f1 = 4.0;
����� cout << �Calling loopit
\n� << loopit ();
}
1. 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 8
followed by the number 2.4?
float loopit ()
{
����� int
a,
����� float
p;
����� cin
>> a >> p;
����� if
(a == 2)
����������������� return
(p * 2.0);
����� else
����������������� return
(p / 2);
}
Answer:��������� �����������������������������������������������������������������������������������������������
����������������� �����������������������������������������������������������������������������������������������
2. 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 4
followed by the number 5.5?
float loopit ()
{
����� int
abc,
����� float
pq;
����� cin
>> abc >> pq;
����� cout
<< endl << �In loopit data read in are � << abc << �
and � << pq;
����� if
(abc� != 0)
����� {���������
����������������� pq
= pq+abc;
����� }
����� return
pq;
}
Answer:��������� �����������������������������������������������������������������������������������������������
����������������������� �����������������������������������������������������������������������������������������������
����������������������� ����������������������������������������������������������������������������������� �����������