lSYCS-135�
Introduction to Programming
Quiz 5 - 10/14/99
Name:� ������������������������������������������������������
For questions 1 and 2 assume the
following main function:
#include <math.h>
#include <iostream.h>
float loopit( int, float& );
void main ()
{
����� int m1 = 2;
����� float f1 = 4.0;
����� cout << �m1 = �
<< m1 << � f1 = � << f1;
����� cout << endl <<
loopit (m1, f1) << endl;
����� cout << �\nm1 = �
<< m1 << � f1 = � << f1;
}
1. [4] What will be printed out
when the program executes using the following definition of loopit?
float loopit(int abc, float&
qq)
{
����� if
(qq <= abc || 3 < sqrt(qq) )
����������������� qq
= qq - 1;
����� else
qq = qq + 1;
����� return
(qq - abc);
}
Answer:��������� �����������������������������������������������������������������������������������
����������������������� �����������������������������������������������������������������������������������
����������������������� �����������������������������������������������������������������������������������
����������������������� �����������������������������������������������������������������������������������
2. [6] What will be printed out
when the program executes, using the following definition of loopit?
float loopit(int abc, float&
pq)
{
����� int
m = abc;
����� while
(m > 0)
����� {
����������������� pq
= pq + m;
����������������� cout
<< � for m =� � << m
<< �� pq =� � << pq << endl;
����������������� m
= m -1;
����� }
����� return
pq;
}
Answer:��������� �����������������������������������������������������������������������������������
����������������� �����������������������������������������������������������������������������������
����������������� �����������������������������������������������������������������������������������
����������������� �����������������������������������������������������������������������������������