Question

In: Computer Science

Original C code please. Part 1: You can do A, B, and C in one program...

Original C code please.

Part 1:

You can do A, B, and C in one program with multiple loops (not nested) or each one in a small program, it doesn’t matter.

A. Create a loop that will output all the positive multiples of 9 that are less than 99.

9 18 27 36 45        ….

B. Create a loop that will output all the positive numbers less than 200 that are evenly divisible by both 2 and 7.

14        28        42        …

C. Create a loop that will calculate the sum of the positive multiples of 8 that are between 100 and 500. Output the sum.

Part 2:

You’re the teacher now! You need 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 (I know, you’re a tough grader!) If there are any grades that are out of the valid range (0 through 100), present an error message to the user, and do not count that grade as passing (or valid). We also would like to see what percentage of the valid grades are passing.

Create 3 test cases. Use this as one of them:

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 are passing.

Create two more sets of test data of your own, and include screenshots of your program running them. Demonstrate all program functionality.

Solutions

Expert Solution

SOLUTION:

Dear Student, I am pasting the code with comments of above query and also attaching it's snapshots .

PART 1 (A, B, C, included in one program):

PROGRAM:

#include <stdio.h>

int main()
{
int i, sum = 0;
// A part print all the positive multiples of 9 that are less than 99
printf("All the positive multiples of 9 that are less than 99\n\n");
for(i=9;i<=99;i++) // for loop start from 9 and run till 99
{
if(i%9==0) //check condition number is divisible by 9 and remainder is 0 then print
{
printf("%d\t", i); // print the numbers
}
}
printf("\n\n");
// B part print all the positive numbers less than 200 that are evenly divisible by both 2 and 7
printf("All the positive numbers less than 200 that are evenly divisible by both 2 and 7\n\n");
for(i=1;i<=200;i++)// for loop start from 1 and run till 200
{
if((i%2==0)&&(i%7==0)) // check condition the number is evenly divisible by both 2 and 7
{
printf("%d\t", i); // print the numbers
}
}
printf("\n\n");
// C part the sum of the positive multiples of 8 that are between 100 and 500
printf("The sum of the positive multiples of 8 that are between 100 and 500\n\n");
for(i=100;i<=500;i++) // for loop start from 100 and run till 500
{
if(i%8==0) // check condition the number is divisible by 8 and remainder is 0
{
sum = sum + i; // calculate the sum
}
}
printf("%d", sum); // print the sum
return 0;
}

SNAPSHOTS:

OUTPUT:

PART 2:

PROGRAM:

#include <stdio.h>
#include <stdlib.h>
int main()
{
// declare variables
int grade, count = 0, count1 = 0, t_grade;
float percentage;
printf("Grade Entered:\t\t\t Expected Result\n");
while(1) // start while loop
{
scanf("%d", &grade); // take inputs from the user
  
if((grade>=70)&&(grade<=100))
{
count++; // count passing grades
}
else if((grade>=0)&&(grade<70))
{
count1++; // count fail grades
}
else if(grade == -1) // if this condition is true then calculate the result & terminate the loop
{
t_grade = count + count1; // calculate total valid count
percentage = (count*100) / t_grade; // calculate percentage of valid count
printf("\t\t\t\tYou entered %d passing grades\n", count);
printf("\t\t\t\t %0.1f %% of the valid grades are passing", percentage);
exit(0); // terminate the while loop
}
else
{
printf("\t\t\t\tThat is not a valid grade!\n");
}
  
  
}
  
  
return 0;
}

SNAPSHOTS:

OUTPUT 1:

OUTPUT 2:

OUTPUT 3:


Related Solutions

You can choose anything you want. Please do fast you can. Please provide an original post...
You can choose anything you want. Please do fast you can. Please provide an original post AND please reply to at least one classmate's post around one of the topics from this week, explaining a topic to the class, discussing a problem that you found particularly difficult, or expanding on something that you learned. To get full points you should have a thoughtful topic or response. You must complete both parts to get full credit. Please see below for an...
IN C++ ONLY... please do both parts of this task ..1 part- Menu driven program First...
IN C++ ONLY... please do both parts of this task ..1 part- Menu driven program First load an array(lists) with the values 3, 4, 84, 5, 2, 47, and 7 in this order by using a function. Then sort the array(list) Use a function to display the menu. Create a program with a menu, with choices 1 for factorial (single value, which everyone will use 20!), 2 for median value , 3 for average, 4 for maximum, 5 for minimum,...
1. Write pseudocode for the following program. You do not have to write actual C++ code....
1. Write pseudocode for the following program. You do not have to write actual C++ code. Assume you have a text file, that has been encrypted by adding 10 to the ASCII value of each character in the message. Design a decryption program that would reverse this process, and display the original message to the console.to the new array. 2.Write the code for the specified program. Use proper style and naming. Test and upload your code as a CPP file....
can someone code this problem please? Introduction Students will create a C++ program that simulates a...
can someone code this problem please? Introduction Students will create a C++ program that simulates a Pokemon battle mainly with the usage of a while loop, classes, structs, functions, pass by reference and arrays. Students will be expected to create the player’s pokemon and enemy pokemon using object-oriented programming (OOP). Scenario You’ve been assigned the role of creating a Pokemon fight simulator between a player’s Pikachu and the enemy CPU’s Mewtwo. You need to create a simple Pokemon battle simulation...
Simple code please thats easy to follow. C++ Write a program that can be used to...
Simple code please thats easy to follow. C++ Write a program that can be used to compare Insertion Sort, Merge Sort and Quick Sort. Program must: Read an array size from the user, dynamically an array of that size, and fill the array with random numbers Sort the array with the Insertion Sort, MergeSort and QuickSort algorithms studied in class, doing a time-stamp on each sort. Use your program to measure and record the time needed to sort random arrays...
Please post all code in Pseudo code. Please post ORIGINAL answers do not copy from similar...
Please post all code in Pseudo code. Please post ORIGINAL answers do not copy from similar questions. Please post in a format that can be directly copied. Reasoning on answers would be most helpful but not required. Thank you in advance for your help. 1. List the following functions according to their order of growth from the lowest to the highest: (n−2)!, 5lg(n+100)10, 22n, 0.001n4 +3n3 +1, ln2 n, √3 n, 3n. 2. The range of afinite nonempty set of...
Code in C++ please You are going to write a program for Computer test which will...
Code in C++ please You are going to write a program for Computer test which will read 10 multiple choice questions from a file, order them randomly and provide the test to the user. When the user done the program must give the user his final score
CODE IN C++ PLEASE Write a program to implement the algorithm that you designed in Exercise...
CODE IN C++ PLEASE Write a program to implement the algorithm that you designed in Exercise 19 of Chapter 1. Your program should allow the user to buy as many items as the user desires. Instructions for Exercise 19 of Chapter 1 have been posted below for your convenience. Exercise 19 Jason typically uses the Internet to buy various items. If the total cost of the items ordered, at one time, is $200 or more, then the shipping and handling...
Code in C# please. Write a program that will use the greedy algorithm. This program will...
Code in C# please. Write a program that will use the greedy algorithm. This program will ask a user to enter the cost of an item. This program will ask the user to enter the amount the user is paying. This program will return the change after subtracting the item cost by the amount paid. Using the greedy algorithm, the code should check for the type of bill. Example: Cost of item is $15.50 User pays a $20 bill $20...
Please can you draw a flow chart for the following code : Program code for Payroll,java:...
Please can you draw a flow chart for the following code : Program code for Payroll,java: public class Payroll { public Payroll(String name,int ID,double payRate) { this.name=name; this.ID=ID; this.payRate=payRate; } private String name; private double payRate,hrWorked; private int ID; public Payroll() { name="John Doe"; ID=9999; payRate=15.0; hrWorked=40; } public String getName() { return name; } public int getID() { return ID; } public void setPayRate(int payRate) { this.payRate=payRate; } public void setHrWorked(double hrWorked) { this.hrWorked=hrWorked; } public double getPayRate() {...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT