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

Programming Paper2 Compilation

The document outlines a series of programming assignments for CS9618, covering various topics such as input/output, selection/conditions, loops, and arrays. Each section includes specific tasks that require the creation of pseudocode programs to perform calculations, conversions, and data handling. The assignments are designed to enhance programming skills through practical applications of algorithms and data structures.

Uploaded by

davis.kazibwe
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)
4 views18 pages

Programming Paper2 Compilation

The document outlines a series of programming assignments for CS9618, covering various topics such as input/output, selection/conditions, loops, and arrays. Each section includes specific tasks that require the creation of pseudocode programs to perform calculations, conversions, and data handling. The assignments are designed to enhance programming skills through practical applications of algorithms and data structures.

Uploaded by

davis.kazibwe
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/ 18

CS9618 PROGRAMMING ASSIGNMENTS FROM INTRODUCTION TO ADVANCED

Input/Output and Assignment


1. Create a pseudocode program to calculate the area of a rectangle. The algorithm should ask the
user to enter the length and width of the rectangle, calculate the area using the formula
area=length*width, and finally display the calculated area as the output.

2. Create a pseudocode program to convert a temperature from Fahrenheit to Celsius. The algorithm
should ask the user to input a temperature in Fahrenheit, perform the conversion using the
formula Celsius = (Fahrenheit-32)*5/9, and output the temperature.

3. Create a pseudocode program to find the sum of two numbers. The algorithm should prompt the
user to enter two numbers, calculate the sum, and display the result as the output.

4. Create a pseudocode program to calculate the area of a circle. The algorithm should ask the user
to enter the radius, calculate the area using the formula area = π * radius * radius, and output
the result.

5. Create a pseudocode program to calculate the average of three numbers. The algorithm should
prompt the user to input three numbers, calculate the average using, and display it as the output.

6. Create a pseudocode program to convert a given time in minutes into hours. The algorithm should
prompt the user to enter a time in minutes, perform the conversion and display the result as hours.

7. Write a pseudocode program to calculate the volume of a sphere. The algorithm should prompt
the user to enter the radius, calculate the volume using the formula volume = (4/3) * π *
radius^3, and display the result.

8. Create a pseudocode program to find the square root of a given number. The algorithm should ask
the user to input a number, calculate the square root using a suitable algorithm (such as Newton's
method), and output the result.

Selection/Conditions
1. Write a pseudocode program to take as input air temperature in degrees Celsius. The program is
to output a message to say whether it is freezing (below 1 degree) or not.

2. Create a pseudocode program that asks the user to input their age. If the age is less than 18,
display a message saying they are a minor; otherwise, display a message saying they are an adult.

3. Create a pseudocode program that prompts the user to enter a passcode. If the entered passcode
matches a predefined value, display a message indicating successful access; otherwise, display a
message indicating access denied. Define a constant variable correctPasscode with the correct
passcode value (“Year13_2023_2024”).

4. Create a pseudocode program to check whether a given number is even or odd. The algorithm
should ask the user to input a number, check its parity using the formula number % 2, and
output whether it's even or odd.

@Davis_Kazibwe_Assignment_Series_Volume1
CS9618 PROGRAMMING ASSIGNMENTS FROM INTRODUCTION TO ADVANCED

5. Write a pseudocode program to determine the maximum of two numbers. The algorithm should
ask the user to enter two numbers, compare them, and output the larger number.

6. Write a pseudocode program that asks the user to input a year. If the year is a leap year (divisible
by 4 and not divisible by 100, or divisible by 400), display a message confirming it's a leap year;
otherwise, display a message stating it's not a leap year.

7. Create a pseudocode program that takes an integer input from the user. If the number is positive,
display a message indicating it's a positive number. If the number is negative, display a message
indicating it's a negative number. If the number is zero, display a message indicating it's neither
positive nor negative.

8. Create a pseudocode program that prompts the user to input a temperature in Celsius. If the
temperature is above 30°C, display a message indicating it's hot. Otherwise, display a message
indicating it's not hot.

9. Create a pseudocode program that asks the user to input the price of an item. If the price is greater
than $50, calculate and display a 10% discount on the price. Otherwise, display the original price.

10. Create a pseudocode program that prompts the user to input their credit score. If the credit score
is above 700, display a message indicating their credit is excellent. If the score is between 600
and 699, display a message indicating their credit is good. Otherwise, display a message
indicating their credit needs improvement.

11. Create a pseudocode program that takes three integer inputs from the user representing the
lengths of three sides of a triangle. Determine and display whether the triangle is equilateral,
isosceles, or scalene. Consider the following instructions
1. If all sides are equal, display "It's an equilateral triangle."
2. If two sides are equal, display "It's an isosceles triangle."
3. If no sides are equal, display "It's a scalene triangle."

12. Create a pseudocode program that asks the user to input a color code (R, G, and B). Use a select
case statement to display the corresponding color name (Red, Green, and Blue).

13. Create a pseudocode program that displays a menu to the user (1. Pizza, 2. Burger, 3. Pasta). Ask
the user to input their choice and use a select case statement to display the chosen item's name.
Consider the following instructions
1. Case 1: Display "You chose Pizza"
2. Case 2: Display "You chose Burger"
3. Case 3: Display "You chose Pasta"
4. Default case: Display "Invalid choice"

@Davis_Kazibwe_Assignment_Series_Volume1
CS9618 PROGRAMMING ASSIGNMENTS FROM INTRODUCTION TO ADVANCED

14. Create a pseudocode program that prompts the user to input a numeric grade (0-100). Use a select
case statement to display a rating (Excellent, Good, Satisfactory, Needs Improvement) based on
the grade range using the following instructions.
1. Case 90 To 100: Display "Excellent"
2. Case 80 To 89: Display "Good"
3. Case 70 To 79: Display "Satisfactory"
4. Case 60 To 69: Display "Fair Good"
5. Case 50 To 59: Display "Fair"
6. Case 70 To 79: Display "Tried"
7. Case Else: Display "Needs Improvement"

15. Write a pseudocode program to take as input an integer between 1 and 12 (inclusive). The
program is to output the name of the month corresponding to the number input. For example, an
input of 2 will output „February‟. Hint: use a CASE statement.

16. Create a pseudocode program that asks for username and password for a successful login.
Consider the following conditions when designing your program
o Correct username: CSKISYR3 and correct password: KIS@2024
o If correct username is entered then ask for a user‟s password and if a correct password
is entered then output, “Access Granted……..Redirecting”.
o Correct username and wrong password output “Wrong Password”
o Wrong username output “Access Denied Wrong Username”
NOTE: Only and only ask for password if the username if correct.

17. Write a pseudocode program that takes the input of a temperature. If the temperature is above
30 degrees Celsius, check if it's a sunny day. If it is sunny, print "Hot and sunny." If it's not sunny,
print "Hot but not sunny." If the temperature is below or equal to 30 degrees, print "Not hot."

18. Create a pseudocode program that takes a student's score and attendance as input. If the score
is above 70 and attendance is 80% or more, print "Pass with distinction." If the score is between
50 and 70 (inclusive) and attendance is at least 70%, print "Pass." Otherwise, print "Fail."

19. Write a pseudocode program for a movie ticket booking system. Ask the user for the age and
whether they are a member. If the age is below 12, provide a 20% discount. If the age is
between 12 and 18 or the user is a member, provide a 10% discount. Otherwise, no discount is
given.

@Davis_Kazibwe_Assignment_Series_Volume1
CS9618 PROGRAMMING ASSIGNMENTS FROM INTRODUCTION TO ADVANCED

Count-controlled loops
1. Write a pseudocode program that prints “Hello KIS” 10 times.

2. Write a program that input 10 names from the user and print “Good Morning” with each name.

3. Write a pseudocode program to take as input a positive integer. The program is to output integers
counting from 1 to the number input. For example, an input of 5 will output: 1 2 3 4 5

4. Amend your program above to count down from the number input to 1. For example, an input of
5 will output: 5 4 3 2 1

5. Amend your program above to take as input a second integer to be used as counting interval. For
example, the input of 20, 4 will output: 1 5 9 13 17

6. Write a pseudocode program to take as input ten numbers and output the largest number.

7. Amend your program above to output the smallest number.

8. Write a pseudocode program that prompts the user to input an integer. Calculate and display the
sum of all even numbers from 1 to the entered number.

9. Write a program that ask 5 numbers from the user and count how many are positive and how
many are negative

Pre-condition and post-condition loops


1. Write a pseudocode program that prints “Hello KIS” 10 times.

2. Write a program that input 10 names from the user and print “Good Morning” with each name.

3. Write a pseudocode program that asks the user for an integer between 1 and 5 (inclusive). The
program is to check that the input is within the range and if not, prompt the user for a valid
integer until the input is within the range.

4. Write a pseudocode program to take as input two positive integers. The program is to output
integers counting from the first integer to the second integer. For example, the input 3, 7 will
output: 3 4 5 6 7

5. Create a pseudocode program that prompts the user to input their age. Ensure that the entered age
is a positive integer. Display an error message and prompt again if the input is invalid
6. Write a pseudocode program that asks the user to input a series of numbers. The program must
keep prompting for input until the user enters -1. Calculate and display the average of the entered
numbers.

7. Create a pseudocode program that prompts the user to input a positive integer. Ensure that the
entered value is indeed positive. Display an error message and prompt again if the input is
invalid.

@Davis_Kazibwe_Assignment_Series_Volume1
CS9618 PROGRAMMING ASSIGNMENTS FROM INTRODUCTION TO ADVANCED

8. Create a pseudocode program that asks the user to input a lowercase letter. Ensure that the
entered character is a vowel. Display appropriate messages based on their input. Consider the
following instructions;
o The program only and only accepts lowercase letter.
o Check if the entered character is a vowel (a, e, i, o, u).
o If a vowel, display "You entered a vowel." and exit the loop.
o If not a vowel, display "Not a vowel. Try again

9. Write a pseudocode program that prompts the user to input a positive integer. Use a repeat until
loop to display a countdown timer from the entered number down to 1.

10. Create pseudocode a program that generates the first 10 odd numbers using a repeat until loop.
Use a counter to limit the number of generated odd numbers.

11. Write a program that ask 5 numbers from the user and print out the largest number.

12. Write a program that ask 5 numbers from the user and count how many are positive and how
many are negative

13. Write a program that ask 5 numbers from the user and print the smallest number.

14. Write a program that ask 20 numbers from the user, computes their average and print it out

15. Create a pseudocode program that prompts a user to guess the correct password “KIS@2023”. If
correct guess output “Genius”, otherwise output “Number of Times Exceeded”. The user is only
allowed to guess the correct password 4 times.

1D Array
1. Write a pseudocode program to declare an array named grades with a size of 5. Initialize it with
the following values: 85, 92, 78, 95, and 88. Display the elements of the grades array.

2. Write a pseudocode program to declare an array named fruits with a size of 6. Initialize it with
the following values: "apple", "banana", "orange", "grape", "kiwi", and "pear". Display the
elements of the fruits array.

3. Write a pseudocode program to declare a Boolean array named flags with a size of 4. Initialize it
with the values: true, false, false, and true. Display the elements of the flags array.

4. Amend the above three programs using loop constructs

5. Write a pseudocode program to create an array and initialize it with ten elements. Each element is
to contain the number 0. The program is to output the contents of the array.

6. Amend your program above so the first element contains 1, the second element contains 2 and so
on.

@Davis_Kazibwe_Assignment_Series_Volume1
CS9618 PROGRAMMING ASSIGNMENTS FROM INTRODUCTION TO ADVANCED

7. Amend your program above. After initialisation the program is to ask repeatedly for an integer
between 1 and 10 until the input is terminated by 0. For each input, the relevant array element
content is to be increased by 1. For example, if the input is 5, the fifth element should be
incremented by 1.

8. Create a pseudocode program that asks names from user and store them into an array called
ResponsibleCitizen. The array is of size 10, output all names stored into an array

9. Write a pseudocode program that asks numbers from the user store them into an array and
afterwards find the average of the stored numbers. The program will stop when the user enters a
zero.

10. Write a pseudocode program, given an integer array named temperatures with 7 elements
representing daily temperatures, find and display the minimum temperature along with its
corresponding date. For example element 1 representing Monday.

11. Write a pseudocode program, given an integer array named sales with 10 elements
representing daily sales amounts, find and display the maximum sales amount along with the
date it occurred. For example element 2 representing day 2

12. Write a pseudocode program, given an integer array named scores containing test scores of
students, calculate and display the sum and average of all the scores.

2D arrays
1. Write a pseudocode program to declare an array called StudentMarks with 5 rows and 4 columns
and initialize each value with 0
2. Write a pseudocode program to Initialise a 5 x 5 array. Each element is to contain the number 0.
The program is to output the contents of the array.
3. Amend your program above. After initialisation the program is to ask repeatedly for two integers
between 1 and 5 until the input is terminated by 0. The two input numbers are to be used as
coordinates and the relevant array element contents is to be increased by 1. For example, if the
first 2 input numbers are 2 and 3, the array contents should be:
00000
00100
00000
00000
00000

Built-in functions
1. Write a program that takes as input a string. The program is to output the number of characters in
the input string.

2. Write a program that takes as input a string. The program is to output the two leftmost characters.

3. Amend your program above to output the two rightmost characters.

@Davis_Kazibwe_Assignment_Series_Volume1
CS9618 PROGRAMMING ASSIGNMENTS FROM INTRODUCTION TO ADVANCED

4. Write a program that takes as input a string. The program is to calculate the middle position and
output the middle character. If the string length is an even number the two middle characters are
to be output.

5. Write a program that takes two input strings: a first name and surname. The program is to
produce the full name by concatenating the first name and surname with a space in between them.
The program is then to output the full name.

6. Amend your program above to produce a name string made up from the first letter of the first
name, a space and the surname.

7. Write a pseudocode program which receives a password and returns valid or invalid to show if a
password is valid or not. A valid password has more than 8 characters, starts with ABC and does
not end with 23.

8. Write a pseudocode program which receives a password and username then returns login
accepted or login denied where login is accepted, the password has more than 4 characters,
usernames starts with letter A and the username ends with letter z.

9. Write a pseudocode program which receives the name of a country and shows either, Uganda,
Kenya or Tanzania by checking if the country name starts with UG, KY or TA.

10. Write a pseudocode program which receive a name and count how many times the name
contains letter z

11. Write a pseudocode program which returns valid or invalid to show if an email address is valid. A
valid email address must have the symbol @, the word Gmail after the @, start with at least
more than 2 characters before the symbol @ and end with the word com.

12. Write a pseudocode program which receives and email address and count how many times the
word @ appears in an email address.

13. Write a pseudocode program which shows if a password is valid or not. A valid password must
have more than 6 characters, atleast one alphabetical letter and one digit.

14. Write a pseudocode program which returns a new password using the firstname, lastname and
email address. The password is a combination of the first 2 letters of the first name followed by
the last 2 letters of the lastname and ends with the word com from the email address. E.g. if my
first name is davis, last name kazibwe , email address [email protected] then the
program should output the password as dawecom

Text files:
Refer To Notes

@Davis_Kazibwe_Assignment_Series_Volume1
CS9618 PROGRAMMING ASSIGNMENTS FROM INTRODUCTION TO ADVANCED

CAMBRIDGE PAST PAPER QUESTIONS PROGRAMMING

Rewrite the algorithm using REPEAT…………….UNTIL

@Davis_Kazibwe_Assignment_Series_Volume1
CS9618 PROGRAMMING ASSIGNMENTS FROM INTRODUCTION TO ADVANCED

@Davis_Kazibwe_Assignment_Series_Volume1
CS9618 PROGRAMMING ASSIGNMENTS FROM INTRODUCTION TO ADVANCED

@Davis_Kazibwe_Assignment_Series_Volume1
CS9618 PROGRAMMING ASSIGNMENTS FROM INTRODUCTION TO ADVANCED

@Davis_Kazibwe_Assignment_Series_Volume1
CS9618 PROGRAMMING ASSIGNMENTS FROM INTRODUCTION TO ADVANCED

@Davis_Kazibwe_Assignment_Series_Volume1
CS9618 PROGRAMMING ASSIGNMENTS FROM INTRODUCTION TO ADVANCED

@Davis_Kazibwe_Assignment_Series_Volume1
CS9618 PROGRAMMING ASSIGNMENTS FROM INTRODUCTION TO ADVANCED

@Davis_Kazibwe_Assignment_Series_Volume1
CS9618 PROGRAMMING ASSIGNMENTS FROM INTRODUCTION TO ADVANCED

@Davis_Kazibwe_Assignment_Series_Volume1
CS9618 PROGRAMMING ASSIGNMENTS FROM INTRODUCTION TO ADVANCED

@Davis_Kazibwe_Assignment_Series_Volume1
CS9618 PROGRAMMING ASSIGNMENTS FROM INTRODUCTION TO ADVANCED

@Davis_Kazibwe_Assignment_Series_Volume1
CS9618 PROGRAMMING ASSIGNMENTS FROM INTRODUCTION TO ADVANCED

@Davis_Kazibwe_Assignment_Series_Volume1

You might also like