Question

In: Computer Science

C++ Coding Exercise (If... Else) Hello All, I know this question has been asked before, but...

C++ Coding Exercise (If... Else)

Hello All, I know this question has been asked before, but I was unable to run any of the programs that were posted and I'm stuck. I would like to see an explanation with the code and exactly how to add a .txt file to the program through VS 2019, if possible.

LAB:

Write a C++ program that computes a student’s grade for an assignment as a percentage given the student’s score and total points. The final score must be rounded up to the nearest whole value using the ceil function in the header file. You must also display the floating-point result up to 5 decimal places. The input to the program must come from a file containing a single line with the score and total separated by a space.

In addition, you must print to the console “Excellent” if the grade is greater than or equal to 90, “Well Done” if the grade is less than 90 and greater than or equal to 80, “Good” if the grade is less than 80 and greater than or equal to 70, “Need Improvement” if the grade is less than 70 and greater than or equal to 60, and “Fail” if the grade is less than 60.

Solutions

Expert Solution

//To add text file in VS 2019

pres CTRL+SHIFT +A

and press Add

//C++ code

#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;

//main()

int main()
{
   //open the file
   ifstream infile("scores.txt");
   cout << fixed << setprecision(5);
   if (!infile)
   {
       cout << "File not found..." << endl;
       return -1;
   }
   double score, totalPoint;
   double percentage = 0;
   while (infile >> score >> totalPoint)
   {
       percentage = ceil((score / totalPoint)*100);
       cout <<"Grade "<<percentage<<" %" << endl;
       if (percentage >= 90)
       {
           cout << "Excellent" << endl;
       }
       else if (percentage < 90 && percentage >= 80)
       {
           cout << "Well Done"<<endl;
       }
       else if (percentage < 80 && percentage >= 70)
       {
           cout << "Good" << endl;
       }
       else if (percentage < 70 && percentage >= 60)
       {
           cout << "Need Improvement"<<endl;
       }
       else
       {
           cout << "Fail" << endl;
       }
   }
   //pause
   system("pause");
}

//File input

//Output

//If you need any help regarding this solution ........... please leave a comment ....... thanks


Related Solutions

This question has been done before but when i submit i receive a type ValueError on...
This question has been done before but when i submit i receive a type ValueError on line 9 where it says index_second_qoutes + 1. Could you please help or update code if needed. Thank U. (Code has been attached at the the end). The votes are in… and it's up to you to make sure the correct winner is announced! You've been given a CSV file called nominees.csv, which contains the names of various movies nominated for a prize, and...
hello i have question in c++ language Q1: create a class called RightTriangleShape, and it has...
hello i have question in c++ language Q1: create a class called RightTriangleShape, and it has data member called height which initialized to 3 by the constructor of the class. It has also the following function members: Void setHeight() to read, and set the height. Void getHeight() to print the value of height. void leftBottom_RTraingle(), prints shape a void leftTop_RTraingle(), prints shape b. void RightTop_RTraingle(), prints shape c. void RigtBottom_RTraingle(), prints shape d. The functions from 3 to 6 have...
Hello, I have been trying to answer this question for the last hour and I am...
Hello, I have been trying to answer this question for the last hour and I am still struggling could someone help me? The deadline is in 1hour! Perform an analysis of variance on the following data set. Do this by answering the questions below. Group 1 Group 2 Group 3 82 87 97 91 90 99 93 91 104 94 99 105 94 101 106 95 115 109 99 118 110 101 114 103 117 105 121 106 121 106...
Question 7 Incomes increase. What else would we need to know before we could determine the...
Question 7 Incomes increase. What else would we need to know before we could determine the impact this change would have on the demand curve for soy milk? Group of answer choices a. Whether soy milk is a normal good or an inferior good b. Whether soy milk is a substitute in consumption or a complement in consumption c. Whether soy milk is supplied or demanded d. We already have enough information to determine the impact on the demand curve...
***I understand this question has already been asked, but could I possibly get a new answer?...
***I understand this question has already been asked, but could I possibly get a new answer? I am trying to study a variety of companies and answers so I will be more prepared for whatever is on the test.*** DoorDash as the company. 1. Select a company that has undergone an initial public offering within the last five years and obtain the prospectus (these are usually available on the company’s website, EDGAR for companies listed on the U. S. stock...
***I understand this question has already been asked, but could I possibly get a new answer?...
***I understand this question has already been asked, but could I possibly get a new answer? I am trying to study a variety of companies and answers so I will be more prepared for whatever is on the test.*** DoorDash as the company. 1. Select a company that has undergone an initial public offering within the last five years and obtain the prospectus (these are usually available on the company’s website, EDGAR for companies listed on the U. S. stock...
******I KNOW THIS QUESTION HAS ALREADY BEEN ANSWERED; HOWEVER I WOULD LIKE A DIFFERENT ANSWER***** With...
******I KNOW THIS QUESTION HAS ALREADY BEEN ANSWERED; HOWEVER I WOULD LIKE A DIFFERENT ANSWER***** With the aid of supply and demand diagrams, explain how each of the following would likely affect the prices and quantities of cigarettes sold in the US. (a) A cure is found for lung cancer. (b) There is a substantial increase in wages in tobacco growing states. (c) A fertilizer that increases the yield per acre of tobacco is discovered. (d) There is a substantial...
Hello, this question relates to a class I am taking called introduction to C++. I have...
Hello, this question relates to a class I am taking called introduction to C++. I have no experience writing programs and outside of learning out of a textbook, and studying on my own, have little understanding of logic. I have been assigned a problem that requires me to write a program for a Grocery Bill, where the consumer inputs the price for 5 items, that the program calculates the total with a 6% sales tax. I really am not sure...
I posted this question before and the person who answered it answered wrong.........please have someone else...
I posted this question before and the person who answered it answered wrong.........please have someone else try again The following information applies to the questions displayed below.] O’Brien Company manufactures and sells one product. The following information pertains to each of the company’s first three years of operations: Variable costs per unit: Manufacturing: Direct materials $28 Direct labor $15 Variable manufacturing overhead $5 Variable selling and administrative $3 Fixed costs per year: Fixed manufacturing overhead $580,000 Fixed selling and administrative...
I have asked this question before however I am not getting the right answer. What is...
I have asked this question before however I am not getting the right answer. What is the evolutionary advantage to having the conduction velocity of neural impulses change with temperature, and which of the five major groups of vertebrate organisms might benefit most from this phenomenon? Explain thoroughly please.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT