100% found this document useful (3 votes)
1K views

C++ Questions Tutorial 2

This document provides examples of programming problems for a structured programming language tutorial. It includes problems such as: 1) Writing a basic calculator program using different control structures. 2) Writing a program to calculate the distance an object falls given time. 3) Writing a program to calculate the arithmetic and harmonic means of two numbers. 4) Writing a program to solve quadratic equations. 5) Writing an animal insurance premium calculator. 6) Writing a program to calculate grades from marks in different components based on a marking scheme. 7) Writing a program to determine if a number is even or odd. 8) Writing a program to determine if a number is positive or negative.

Uploaded by

anon-75475
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
1K views

C++ Questions Tutorial 2

This document provides examples of programming problems for a structured programming language tutorial. It includes problems such as: 1) Writing a basic calculator program using different control structures. 2) Writing a program to calculate the distance an object falls given time. 3) Writing a program to calculate the arithmetic and harmonic means of two numbers. 4) Writing a program to solve quadratic equations. 5) Writing an animal insurance premium calculator. 6) Writing a program to calculate grades from marks in different components based on a marking scheme. 7) Writing a program to determine if a number is even or odd. 8) Writing a program to determine if a number is positive or negative.

Uploaded by

anon-75475
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

CSC 1101 Structured programming language

Tutorial II
Prepared by: Showayb Zahda
Solve the following problems:
1. Calculator, make your own calculator that does the four basic arithmetic operations i.e. +, -, *, /.
using switch
using if statements
using if else statements.
(Note: use functions for the arithmetic operations)

2. Consider a brick that is dropped from a tower. The distance the brick falls depends on the the
time since it was released.
d = (1/2) g t2
Here d is the distance in feet, t is the time in seconds, and g is 32.174. Write a program that asks
the user for the number of seconds and then prints out the distance.
Enter the number of seconds
5.4
Distance: 469.092 feet

3. The harmonic mean of two numbers is given by:


H = 2 / ( 1/X + 1/Y )
This is sometimes more useful than the more usual average of two numbers. Write a program
that inputs two numbers (as floating point) and writes out both the usual average (the arithmetic
mean) and the harmonic mean.
Enter X:
12
Enter Y:
16
Arithmetic mean: 14.0
Harmonic mean: 13.714285714285715

4. Quadratic Equation, write a programme that finds the roots of a quadratic equation.
Ax2 + Bx + C = 0

5. Animal insurance
Write a program that prints the insurance fee to pay for a pet according to the following rules:
• A dog that has been neutered costs $50.
• A dog that has not been neutered costs $80.
• A cat that has been neutered costs $40.
• A cat that has not been neutered costs $60.
• A bird or reptile costs nothing.
• Any other animal generates an error message.

The program should prompt the user for the appropriate information, using a code to determine
the kind of animal (i.e. D or d represents a dog, C or c represents a cat, B or b represents a bird,
R or r represents a reptile, and anything else represents some other kind of animal).
After printing the insurance fee, the program should ask the user if (s)he wants to insure another
animal.
6. KICT has a new marking scheme which is
1. 2 quizzes each carries 5 %.
2. 3 assignments each carries 10 %
3. Mid-term carries 20 %
4. mini project carries 10 %
5. final exam carries 30 %
you are asked to develop a system that reads the marks from the keyboard and computes
the grade out of 100 %. Then the system shall output the letter corresponds to the mark
based on the following table

Mark letter
Above 85 A
75 – 84 A-
70 – 74 B+
65 – 69 B
60 – 64 B-
55 – 59 C+
50 – 54 C
Below 49 D
Hint: use if – else statements and use functions when appropriate

7. Write a programme to determine whether a number is even or odd. Hint: use %

8. Write a programme that determines whether the number is positive or negative.

You might also like