Part 2 (10% points) Evaluate the Relational and Logical expressions in Video Seg
ID: 3915854 • Letter: P
Question
Part 2 (10% points) Evaluate the Relational and Logical expressions in Video Segment 9.8
https://www.youtube.com/watch?v=_fHXQFCsdtY&feature=youtu.be&t=16m29s
Put these expressions in a small program that will demonstrate whether they are true or false. Paste the code, and output from the program into your submission. Use if statements and output a message indicating that the expression is True or False.
Part 3 (80% points) Write a C program (with meaningful comments) to solve a problem described in English. Create an IPO.
We want to count how many passing grades are entered. We don’t know how many grades there will be. Use a sentinel controlled while loop that will ask the user to enter student grades until a value of -1 is entered. Use a counter variable to count all the grades that are passing grades, where 70 is the minimum passing grade. If there are any grades that are out of the range 0 – 100, present an error message to the user, and do not count that grade as passing. We also would like to see what percentage of the valid grades are passing.
Create two more test cases.
Use following one in addition to the two you create.
Grades Entered: Expected Results
45
90
70
87
123 “That is not a valid grade!”
100
-1 You entered 4 passing grades.
80.0% of the valid grades entered are passing grades.
Deliverables: Paste code, program output and screen shots into this Word document. Presenting your solution is part of the assignment.
The message in email once part 1 is done. (1 point)
Solution to Part 2 (paste code and screen shot/s of the output window) – solution to the relational/logical expressions. (1 point)
An IPO for the problem in Part 3.(1 point)
Two test cases that show two sets of input data, and the expected results of running the program for each set of input data. These are to be written separately before running the program and taking the screen shots. ( 0.5 points)
The code that solves the passing grades problem. Remember to use meaningful comments. (6 points)
Output from running the program 3 different times. Use two test cases that you created and the one I have given you. (0.5 points)
Explanation / Answer
Solution to Part2:
#include <stdio.h>
int main()
{
int a = 5, b =4, c=3,d=2;
if(a <= b + 1) {
printf("a <= b+1 : Holds True ") ;
}else{
printf("a <= b+1 : Holds FALSE ") ;
}
if(a < b && c >b) {
printf("a < b && c >b : Holds True ") ;
}else{
printf("a < b && c >b : Holds FALSE ") ;
}
if(a >= c || d >= 5) {
printf("a >= c || d >= 5 : Holds True ") ;
}else{
printf("a >= c || d >= 5 : Holds FALSE ") ;
}
if( !(a>b)) {
printf("!(a>b) : Holds True ") ;
}else{
printf("!(a>b) : Holds FALSE ") ;
}
if(b>=a && !(d<b)) {
printf(" b>=a && !(d<b) : Holds True ") ;
}else{
printf(" b>=a && !(d<b) : Holds FALSE ") ;
}
return 0;
}
--OUTPUT---
a <= b+1 : Holds True
a < b && c >b : Holds FALSE
a >= c || d >= 5 : Holds True
!(a>b) : Holds FALSE
b>=a && !(d<b) : Holds FALSE
PART3:
Solution:
/******************************************************************************
Online C Compiler.
Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <stdio.h>
int main()
{
int testInteger,totalInputs,inValidGrades,numberOfPassingGrades;//declaring variables to be used
inValidGrades=0;//initializing inValidGrades as 0
totalInputs=0;//initializing totalInputs as 0
numberOfPassingGrades= 0;//initializing numberOfPassingGrades as 0
int passingGrade =70;//declaring and initializing passing Grade value
scanf("%d",&testInteger);//taking testInteger as input number
while(testInteger != -1){//if it is -1 then we do not take more inputs else we do computation
++totalInputs;//increase totalInputs count by 1
int isInValid = 0;//isInValid by default =0 indicating testInteger is valid. When known testInteger is invalid mark isInValid =1
if(testInteger >100 || testInteger<0){//validating logic for numbers between 0-100
printf("This grade is not a valid grade! ");
++inValidGrades;
isInValid = 1;//marking isInValid = 1 indicating number is inValid
}
if(testInteger >= passingGrade && isInValid == 0){ //checking is integer > passing score and is valid then only increase numberOfPassingGrades
++numberOfPassingGrades;
}
scanf("%d",&testInteger);
}
printf("You have entered %d passing grades. ",numberOfPassingGrades);
if (numberOfPassingGrades <= 0.0){
printf( "0.0 of the valid grades entered are passing grades.");
}else{
double passingGradePercent = numberOfPassingGrades * 100.00/ (totalInputs-inValidGrades);//calculate %age
printf( "%f of the valid grades entered are passing grades.",passingGradePercent);
}
return 0;
}
---OUTPUT 1-----
45
70
90
87
123
This grade is not a valid grade!
100
-1
You have entered 4 passing grades.
80.000000 of the valid grades entered are passing grades.
---OUTPUT 2-------------
00
-2
This grade is not a valid grade!
20
10
80
90
-1
You have entered 3 passing grades.
60.000000 of the valid grades entered are passing grades.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.