0% found this document useful (0 votes)
4 views2 pages

PR621AD Mock Test 1

The document covers fundamental concepts of functions in programming, including return types, function declarations versus definitions, function overloading, and the importance of parameters. It also includes C++ code snippets with expected outputs and programming exercises that involve array manipulation, user input, and function creation. The exercises require writing code to handle user input, display results, and implement a function to check for even numbers.

Uploaded by

Miguel Carvalho
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

PR621AD Mock Test 1

The document covers fundamental concepts of functions in programming, including return types, function declarations versus definitions, function overloading, and the importance of parameters. It also includes C++ code snippets with expected outputs and programming exercises that involve array manipulation, user input, and function creation. The exercises require writing code to handle user input, display results, and implement a function to check for even numbers.

Uploaded by

Miguel Carvalho
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Section A: Theory

1.1 What is the purpose of a return type in a function declaration?


1.2 What is the difference between a function declaration and a function definition?
1.3 Explain the concept of function overloading with an example.
1.4 Why should functions use parameters instead of relying only on global variables?

Section B: Code Output

For each of the following C++ code snippets, write the output as it will appear on the screen.

2.1 2.2
#include <iostream> #include <iostream>
using namespace std; using namespace std;

int main() { int main() {


for(int i = 1; i <= 3; for(int i = 3; i >= 1; i--)
i++) { {
for(int j = 1; j <= i; for(int j = 1; j <= i;
j++) { j++) {
cout << "*"; cout << j;
} }
cout << endl; cout << endl;
} }
return 0; return 0;

Section C: Programming Questions

3.1 Write a program that does the following:


 Declares an array of 5 integers
 Allows the user to input values into the array
 Prints the array in reverse order

3.2 Write a program that:


 Prompts the user to enter a floating point number
 Displays the square root and the power of that number raised to 3
3.3 Write a function called isEven that takes an integer parameter and returns true if it is even,
otherwise false. In main(), read an integer from the user and use the function to
determine if it is even or not.

You might also like