100 likes | 117 Views
Practice coding with problems like determining even/odd, calculating circle area, finding the greater of two numbers, and classifying triangles based on side lengths. Prepare for an upcoming quiz by solving flowcharts and writing pseudo code in C++. Utilize Lab exercises for hands-on learning.
E N D
Lecture 2 Examples Pseudo code and flowcharts
Problem 1 • Read a number as input and then print if it is even or odd
Problem 1 : Flowchart and pseudo code Pseudo code: read number get the remainder when the number is divided by 2 if remainder is 0 print “number is even” else print “number is odd”
Problem 2 • Read the radius of circle and print the area and circumference only if the value of the radius is more than zero.
Problem 2 Pseudo code: read radius if radius <= 0 print “Radius cannot be negative or zero” exit if radius > 0 calculate area calculate circumference print area print circumference
Problem 3 • Take two numbers as input and print the greater of the two. If numbers are equal print “numbers are equal”.
Problem 3 Pseudo code: read n1, n2 if n1 equals n2 print “numbers are equal” exit if n1 > n2 print “n1 is greater” else print “n2 is greater”
Problem 4 • Read the length of the three sides of a triangle and print if it the triangle is an equilateral or isosceles or scalene triangle. equilateral – all sides are equal isosceles – any two sides are equal scalene – all sides have different length Try this problem as an exercise and show it to me in the labs
Quiz 1 • Next week at this lecture time • 45 mins, 5% of the course • Lecture 1 + Lecture 2 part (what we did today) • MCQs, short answer, flowcharts, pseudo code and c++ programs
Lab talk • DevC++ is already setup for most of you • Always come to lab with the lecture printout or PPT • Lab exercises are related directly to lecture and are the practical part of the lecture • YOU MUST TRY TO SOLVE THE LAB EXERCISES BEFORE YOU COME TO LAB – TRY! • Save and organize your C++ programs into folders like lab 1, lab 2 – you will need them later…. • There are lab exams also .. later • Lab exercises always available on the website a couple of days before the lab