SP Lab 3-Section 1
SP Lab 3-Section 1
Total Mark / 10
Lab #3 Objectives
● equality and relational operators
● logical operators (AND, OR, NOT)
● Equality (==) and assignment (=) Operators.
● precedence of operators
● if selection statement
● if ...else selection statement
● The conditional operator ( ?:)
● nested if ... else statements
● switch multiple-selection statement
●
Page 1 of 5
Part I: Lab Example
Example – Student Grade Evaluator
The student will implement a simple grade evaluation system where:
Introduction:
The student will implement a simple grade evaluation system where:
Steps to Follow:
Define a function getGrade() that:
o Takes the score as a parameter.
o Returns the letter grade based on standard grading criteria.
If the score is out of range (less than 0 or more than 100), return '0'.
If the score between 90 and 100 return A
If the score between 80 and 90 return B
If the score between 70 and 80 return C
If the score between 60 and 70 return D
If the score between 50 and 60 return E
If the score less than 50 return F
Define another function printMessage() that:
o Takes the letter grade as a parameter.
o Uses a switch statement to print feedback based on the grade (See code below).
Inside the main () function:
o Declare an integer variable to store the randomly generated score.
o Use rand () to generate a random score between -10 and 110.
o Call getGrade() to determine the letter grade.
o Display the generated score and letter grade using printf().
Call printMessage() to display an appropriate message.
Sample Output
Page 2 of 5
Solution
Page 3 of 5
PART II: Lab Exercise
On the desktop, create a folder named Lab3 followed by your id inside it Create project named
Lab3Ex1.
Problem Description
Create a program that determines if the number is a Odd , or the number is Even or the number is equal
to zero. The program will print the state of the number and the number too.
Steps to follow:
Sample Output
Page 4 of 5
PART III: Extra Lab Exercises
Exercise 1 –Character Classification: Check if a Character is a Letter
Note:
Capital letter Alphabets (A-Z) lie in the range 65-91 of the ASCII value
Small letter Alphabets (a-z) lie in the range 97-122 of the ASCII value
Any other ASCII value is a non-alphabetic character.
Sample Output
Enter Character
A
A is letter
Enter Character
5
5 is not letter
Sample Output
Page 5 of 5