Assignment 3
Programming Fundamentals
Instructions:
• Write the C++ programs for the given problems.
• Ensure proper use of if, if-else, if-else-if-else, switch, and nested if-else statements and for
loops, while loops and do-while loops and user-defined functions wherever applicable.
• Use cin for input and cout for output.
• Comment on each step of your code.
• Ensure the proper use of indentation and brackets in the programs.
• Submit your solution as a .cpp file with name as SAP-ID_Name_Assignment3.cpp with all of
the questions’ codes written inside of it, each code running individually on their own and
add a comment on the top as the question number.
Total Marks: 10
Submission Deadline: 11:59 p.m., June 14, 2025.
Q1: Write a program that takes two positive integers from the user: a start and an end value.
You must:
• Use a function isPrime(int n) that returns true if n is a prime number.
• Loop through all numbers in the given range and display only the prime numbers using the
function.
Also, count how many primes were found and display the total at the end.
Q2: Create a calculator that inputs two numbers and presents the user with the following menu:
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Exit
Each operation must be implemented in a separate function which accepts two numbers and
returns the result. The program should keep showing the menu until the user chooses Exit.
NOTE: For division, check for division by zero and display an error if attempted.