0% found this document useful (0 votes)
7 views7 pages

Tutorial 2

The document outlines a tutorial for EE171: Principles of Computer Programming, focusing on control structures. It presents eight programming problems involving decision-making, loops, and control statements, such as determining pass/fail status, grading systems, and basic calculator functions. Each problem includes a scenario and specific tasks to be completed using various programming constructs.

Uploaded by

Nickson Gashuhe
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)
7 views7 pages

Tutorial 2

The document outlines a tutorial for EE171: Principles of Computer Programming, focusing on control structures. It presents eight programming problems involving decision-making, loops, and control statements, such as determining pass/fail status, grading systems, and basic calculator functions. Each problem includes a scenario and specific tasks to be completed using various programming constructs.

Uploaded by

Nickson Gashuhe
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

DEPARTMENT OF ELECTRICAL ENGINEERING

EE171: Principles of Computer Programming

TUTORIAL TWO 2025/2026

Control Structures

PROBLEM 1: Student Pass/Fail Decision (if statement)


Problem Scenario

A university system must determine whether a student passes or fails based on the marks
obtained.

Task

 Input marks (0–100)


 If marks ≥ 50 → PASS
 Else → FAIL

PROBLEM 2: Grading System (Nested if–else)


Problem Scenario

Grades are assigned based on marks:

 ≥ 75 → A
 ≥ 65 → B
 ≥ 50 → C
 < 50 → F

Task

Design a grading program using nested if–else.


PROBLEM 3: Menu-Based Calculator (switch statement)
Problem Scenario

Create a simple calculator for basic operations.

Task

 Ask user to choose an operation


 Perform addition, subtraction, multiplication, or division

PROBLEM 4: Multiplication Table (for loop)


Problem Scenario

A student wants to print the multiplication table of any number.

Task

Use a for loop to display a table up to 10.

PROBLEM 5: Sum of Natural Numbers (while loop)


Problem Scenario

Calculate the sum of numbers from 1 to N.

Task

Use a while loop.

PROBLEM 6: Password Validation (do–while loop)


Problem Scenario

The system keeps asking for a password until the correct one is entered.

Task

Use do–while loop.


PROBLEM 7: Skip Even Numbers (continue statement)
Problem Scenario

Display only odd numbers from 1 to 10.

Task

Use continues to skip even numbers.

PROBLEM 8: Stop at Negative Input (break statement)


Problem Scenario

A system reads numbers until a negative number is entered.

Task

Use break to terminate the loop.


SOLUTIONS
PROBLEM 1: PROBLEM 2:
PROBLEM 3:
PROBLEM 4: PROBLEM 6:

PROBLEM 5:
PROBLEM 7:
PROBLEM 8

You might also like