Question

Write a C++ program that computes student grades for an assignment as a percentage given each students score and the total p
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the code:

#include <iostream>

#include <fstream> //for inputting the file

#include <string>

#include <cmath>

#include <iomanip> //for precision purpose

using namespace std;

// this function is used to print the name of the student in output

void print_name(string lastName)

{

cout << lastName << " ";

}

// this function prints remarks based on percentage of user

void print_remark(int per)

{

if (per > 90)

{

cout << "Excellent";

return;

}

if (per > 80 && per <= 90)

{

cout << "Well done";

return;

}

if (per > 70 && per <= 80)

{

cout << "Good";

return;

}

if (per >= 60 && per <= 70)

{

cout << "Need Improvement";

return;

}

if (per >= 50 && per < 60)

{

// no condition given for range 50-60

//would not do anything .....

}

if (per < 50)

{

cout << "Fail";

return;

}

}

int main()

{

string filePath;

cout << "Please mention the filepath: ";

cin >> filePath;

//to read data from the file

ifstream inputFile(filePath);

string lastName;

int obtained, maximum;

//every line of the file will be assumed to have one string

//and two numbers and will be read token by token.

while (inputFile >> lastName >> obtained >> maximum)

{

double per, per1;

//calculate percentage

per = (double)obtained / maximum;

per1 = per * 100;

print_name(lastName);

// here instead of just using integer part of per1

// u can use 'ceil' or 'floor' function as per your convenience

//using ceil function will get you 84(nearest upper integer) for .83333 and floor will get us 83(nearest lower integer)

// You can use ceil or floor instead of int below accordingly.

cout << (int)per1;

cout << "% ";

// std::fixed is used for printing trailing zeroes in decimal part eg:- 8.5000

// setprecision fixes the number of digits you want to print after decimal

cout << std::fixed;

cout << setprecision(5) << per << " ";

// this function prints necessary remarks based on percentage

print_remark((int)per1);

cout << "\n";

}

return 0;

}

Add a comment
Answer #2

#include <iostream>

#include <fstream> //for inputting the file

#include <string>

#include <cmath>

#include <iomanip> //for precision purpose

using namespace std;

// this function is used to print the name of the student in output

void print_name(string lastName)

{

cout << lastName << " ";

}

// this function prints remarks based on percentage of user

void print_remark(int per)

{

if (per > 90)

{

cout << "Excellent";

return;

}

if (per > 80 && per <= 90)

{

cout << "Well done";

return;

}

if (per > 70 && per <= 80)

{

cout << "Good";

return;

}

if (per >= 60 && per <= 70)

{

cout << "Need Improvement";

return;

}

if (per >= 50 && per < 60)

{

// no condition given for range 50-60

//would not do anything .....

}

if (per < 50)

{

cout << "Fail";

return;

}

}

int main()

{

string filePath;

cout << "Please mention the filepath: ";

cin >> filePath;

//to read data from the file

ifstream inputFile(filePath);

string lastName;

int obtained, maximum;

//every line of the file will be assumed to have one string

//and two numbers and will be read token by token.

while (inputFile >> lastName >> obtained >> maximum)

{

double per, per1;

//calculate percentage

per = (double)obtained / maximum;

per1 = per * 100;

print_name(lastName);

// here instead of just using integer part of per1

// u can use 'ceil' or 'floor' function as per your convenience

//using ceil function will get you 84(nearest upper integer) for .83333 and floor will get us 83(nearest lower integer)

// You can use ceil or floor instead of int below accordingly.

cout << (int)per1;

cout << "% ";

// std::fixed is used for printing trailing zeroes in decimal part eg:- 8.5000

// setprecision fixes the number of digits you want to print after decimal

cout << std::fixed;

cout << setprecision(5) << per << " ";

// this function prints necessary remarks based on percentage

print_remark((int)per1);

cout << "\n";

}

return 0;

}


Add a comment
Know the answer?
Add Answer to:
Write a C++ program that computes student grades for an assignment as a percentage given each...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Microsoft Visual Studios 2017 Write a C++ program that computes a student’s grade for an assignment...

    Microsoft Visual Studios 2017 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 <cmath> 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...

  • Write a C++ program that computes a student’s grade for an assignment as a percentage given...

    Write a C++ program that computes a student’s grade for an assignment as a percentage given the student’s score and the total points. The final score should be rounded up to the nearest whole value using the ceil function in the <math> header file. You should 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. If...

  • please use the c language Assignment 12 The program to write in this assignment is a...

    please use the c language Assignment 12 The program to write in this assignment is a program that calculates score statistics and manages the grades of the students. First, the student list and are given in a file named "student.dat" as in the following: 이성우 77 홍길동 88 scores 201 1710086 2012700091 This program reads the input file "student.dat" and keeps this data in a linear linked list. Each node must be a struct which contains the following: student id...

  • in C porgraming . use #include〈stdio.h〉 #include〈stdlib.h〉 Assignment 12 The program to write in this assignment...

    in C porgraming . use #include〈stdio.h〉 #include〈stdlib.h〉 Assignment 12 The program to write in this assignment is a program that calculates score statistics and manages the grades of the students. First, the student list and scores are given in a file named "student.dat" as in the following: 이성우 77 홍길동 88 2011710086 2012700091 This program reads the input file "student.dat" and keeps this data in a linear linked list. Each node must be a struct which contains the following: student_id,...

  • Write a C program to compute average grades for a course. The course records are in...

    Write a C program to compute average grades for a course. The course records are in a single file and are organized according to the following format: Each line contains a student’s first name, then one space, then the student’s last name, then one space, then some number of quiz scores that, if they exist, are separated by one space. Each student will have zero to ten scores, and each score is an integer not greater than 100. Your program...

  • C++ Write a program that reads students’ names followed by their test scores from the given...

    C++ Write a program that reads students’ names followed by their test scores from the given input file. The program should output to a file, output.txt, each student’s name followed by the test scores and the relevant grade. Student data should be stored in a struct variable of type StudentType, which has four components: studentFName and studentLName of type string, testScore of type int and grade of type char. Suppose that the class has 20 students. Use an array of...

  • Write a complete C++ program that reads students names and their test scores from an input...

    Write a complete C++ program that reads students names and their test scores from an input text file. The program should output each student’s name followed by the test scores and the relevant grade in an output text file. It should also find and display on screen the highest/lowest test score and the name of the students having the highest/lowest test score, average and variance of all test scores. Student data obtained from the input text file should be stored...

  • Implement a C program to calculate the Average Score Point(ASP) of a student taking N courses...

    Implement a C program to calculate the Average Score Point(ASP) of a student taking N courses in a semester. Ask the user for the number of courses(N) the student is taking in the semester, and check if the number of courses is greater than 1 (>1). If the number of courses is less than or equal to 1(<=1), display an error and ask the user to try again until the right input is entered. Next, ask the user for the...

  • Write a C++ program to store and update students' academic records in a binary search tree....

    Write a C++ program to store and update students' academic records in a binary search tree. Each record (node) in the binary search tree should contain the following information fields:               1) Student name - the key field (string);               2) Credits attempted (integer);               3) Credits earned (integer);               4) Grade point average - GPA (real).                             All student information is to be read from a text file. Each record in the file represents the grade information on...

  • This is in C++. Example: You will write a program that will prompt the user to...

    This is in C++. Example: You will write a program that will prompt the user to enter a grade out of 100 and then show them what the equivalent grade points value is. The main() function will handle the input and output tasks, but the actual conversion will occur in a function called GradePoints(). GradePoints Specifications This function is strictly a processing function, meaning that there are no console input or output steps in the actual function. Consider that this...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT