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

Week 3

Uploaded by

24019065027
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)
8 views7 pages

Week 3

Uploaded by

24019065027
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/ 7

Programming Fundamentals

CC111
Saleha Batool
Lecturer KUST
UMT Sialkot
Problem Solving
 Define the Goal: What is the desired outcome?
 Identify Input/Output: What data do we need, and what should the
output look like?
 Divide into Smaller Steps: Tackle one part at a time.
 Use Pseudocode: Write a high-level version of the solution.
 Use of Variables
 Input/Output
 Operators
 Control Structures

Programming Fundamentals 2
Programming Practice
 Write a program to calculate the product of three integers:
oDeclare the variables x, y, z and result to be of type int (in separate
statements).
oPrompt the user to enter three integers.
oRead three integers from the keyboard and store them in the
variables x, y and z.
oCompute the product of the three integers contained in variables x, y
and z, and assign the result to the variable result.
oPrint "The product is " followed by the value of the variable result.
oReturn a value from main indicating that the program terminated
successfully.
Programming Fundamentals 3
Programming Practice
 Write a program to calculate the age of a person based on their year
of birth:
 Declare the variables name, education, yearOfBirth, and age to be of type
string and int (in separate statements).
 Prompt the user to enter their name, education, and year of birth.
 Read the name, education, and year of birth from the keyboard and store
them in the respective variables.
 Compute the age by subtracting yearOfBirth from the current year (e.g.,
2024) and assign the result to the variable age.
 Print a message in the following format:
"Hello [name]! You are [age] years old and your education level is
[education].“
Programming Fundamentals 4
Programming Practice
 Write a program to add two floating-point numbers and display the sum:
 Declare the variables num1, num2, and sum to be of type float.
 Prompt the user to enter two floating-point numbers.Read the two numbers from
the keyboard and store them in the variables num1 and num2.
 Compute the sum of num1 and num2 and assign the result to the variable sum.
 Print the output in the following format:
"[num1] + [num2] = [sum]“
For example, if num1 is 24.27 and num2 is 41.50, the output should be:
24.27 + 41.50 = 65.77

Programming Fundamentals 5
Programming Practice
 Write a program to print a right-angled triangle pattern of asterisks
as shown below:
*
**
***
****
You can only use cout stataments.

Programming Fundamentals 6
Programming Practices
 Write a program to display the ASCII value of a given character.
 Write a program to swap the values of two variables using a third
variable.
 Write a program to swap values of two variables without using a
third variable.

Programming Fundamentals 7

You might also like