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

Hello everyone! I have been stuck on this problem in my python 3 coding class. Is...
Hello everyone! I have been stuck on this problem in my python 3 coding class. Is there anybody who can see what I am doing wrong? The wings are .50 cents each, If I input sour and want 20 wings it should output a 0.15 discount. I just can't get it to work but I feel like I am really close. Thank you Code: #Variables answer = str() wings = int() rate = float() discount = float() subtotal = float()...
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...
Python Coding Question (Data Science) Hello I am having difficulty writing a code in python to...
Python Coding Question (Data Science) Hello I am having difficulty writing a code in python to do a specific task. I have two text files, Positive.txt and Practice_forhw1.txt. I want to write a script that will check if any words in Practice_forhw1.txt match any of the words in Positive.txt then the word would get replaced with a "+1" in the Practice_forhw1.txt and then print out the Practice_forhw1.txt.  (i.e if the word "happy" is in both Positive.txt and Practice_forhw1.txt then I want...
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 this question that I have been trying to solve for days. I am...
Hello, I have this question that I have been trying to solve for days. I am always able to solve the first part of the question, but I am never able to get the second part. Please help me understand how to set up this problem so I am able to solve it! Q: Let's revisit the banked curves from earlier to see another reason they are useful.We are building a road, and at one place we need to make...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT