Name_______________________
Login___________________SID________
CS 010: Introduction to
Computer Science I
#include
<iostream>
using
namespace std;
void
do_something(int& x)
{
x = x * 2;
}
int
main()
{
int a = 1;
while (a < 10)
{
cout << a << “ “;
do_something(a);
}
return 0;
}
a. 1 2 3 4 5 6 7 8 9
b.
1
2 4 8
c. 8
d. 16
e. Infinite loop, program never ends
f. Program will not compile
??????
{
int product = 1;
for (int i = 1; i < n; i++)
{
product = product * i;
}
return product;
}
a. void factorial()
b. int factorial()
c. int factorial(int& n)
d.
int
factorial(int n)
??????
{
a = n;
b = n * n;
return;
}
a. void do_something()
b. void do_something(int a, int b, int n)
c. void do_something(int& a, int& b, int& n)
d. int do_something(int& a, int& b, int& n)
e.
void
do_something(int& a, int& b, int n)
f. int do_something(int a, int b, int& n)
Use the following function prototypes (declarations)
for the next 2 questions.
void
func1(int n, double m, string s);
int
func2(int& n);
bool
func3(int n);
a. func1(10, 20.0, “abc”);
b. func1(func2(n1), d1, s1);
c. if (func3(n1)) cout << s1;
d. n1 = func2(n1);
e.
cout
<< func2(func1(n1, d1, s1));
f. B and E
!(m
< n && o == p)
m
> n || !(o <= p && q > r)
int
i;
for
(i = 0; i < 5; i = i + 2)
{
cout << i << “ “;
}
cout
<< i << endl;