0% found this document useful (0 votes)
3 views3 pages

Fundamentals of Programming Tutorial Sheet

The document is a tutorial sheet with programming questions covering various fundamental concepts in programming, including error types, data types, loops, modular programming, object-oriented programming, and algorithms. It includes tasks such as writing pseudocode, correcting code, and explaining programming principles. The questions aim to test understanding of programming languages like C++ and Java, as well as software development practices.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Fundamentals of Programming Tutorial Sheet

The document is a tutorial sheet with programming questions covering various fundamental concepts in programming, including error types, data types, loops, modular programming, object-oriented programming, and algorithms. It includes tasks such as writing pseudocode, correcting code, and explaining programming principles. The questions aim to test understanding of programming languages like C++ and Java, as well as software development practices.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

FUNDAMENTALS OF PROGRAMMING

TUTORIAL SHEET

Answer all questions

1. What is the difference between a runtime error and a logical error? Give one clear
example of each in C++ or Java and explain how to detect and correct them.
2. Define a literal in programming and explain how it differs from a variable. Give examples
of two types of literals used in Java or C++.
3. Write a pseudocode or simple program that uses a do-while loop to keep prompting a
user until they enter a number between 1 and 10.
4. Explain what a data type is and why selecting the right data type matters in
programming. Give examples of two different numeric data types and their common use
cases.
5. Analyze the following code and correct all mistakes. Then explain what the corrected
code does.

#include <iostream>
using namespace std;

float findAverage(int nums[], int length) {


float sum;
for (int i = 0; i <= length; i++)
sum += nums[i];
return sum / length;
}

int main() {
int data[5];
float result;

for (int i = 0; i < 5; ++i)


cout << "Enter number: ";
cin >> data[i];

result = findAverage(data, 5);


cout << "Average is: " << result << endl;
return 0;
}
6. Describe how you would calculate the average of 6 numbers stored in an array. Then
explain why using a function to do this is better than writing the logic inside the main()
function.
7. You have temperature readings for 7 days stored in an array. Describe how you would:
Calculate the total temperature, Find the average, Count how many readings were above
the average.
8. What is modular programming? Write pseudocode with three functions: one to collect
user input, one to calculate a total, and one to display the result. Use student scores as
an example.
9. Why is testing important in software development? Create two test cases for a function
that checks whether a number is prime. Include the input and expected output.
10. Briefly explain the following object-oriented programming concepts in your own words:
Encapsulation, Inheritance, Polymorphism, Abstraction. Use a class example (e.g.,
Student or BankAccount).
11. What is the purpose of the ‘break’ and ‘continue’ statements in loops? Give examples to
show how each works.
12. Write a program or pseudocode to find the maximum and minimum values in an array
of 10 integers.
13. Describe how a function is defined and called in C++. Write a simple function that
returns the square of a number.
14. Explain the difference between passing arguments by value and by reference in a
function. Provide an example of each.
15. What is an array? How does it differ from a single variable? Why is it useful in storing
multiple values?
16. Write a C++ program that accepts 5 numbers from a user, stores them in an array, and
then prints only the even numbers.
17. Explain the use of the ‘const’ keyword in C++ or Java. Why would you declare something
as constant?
18. Describe what a class is in object-oriented programming. Create a simple class example
for a Book with attributes and a method.
19. What is an algorithm? Write an algorithm to check whether a number entered by a user
is positive, negative, or zero.
20. Differentiate between global and local variables with examples. When should each be
used?
21. Explain how selection (decision making) is implemented in programming. Show an
example using if-else and switch statements.
22. Describe how a nested loop works. Write a program to print a multiplication table (1 to
5).
23. What is a vector in C++? How does it differ from an array? Give one benefit of using
vectors.

You might also like