Question

In: Computer Science

Module/Week 3 ASSIGNMENT (CONTROL STRUCTURES . IF ..ELSE) Write a C++ program that computes a student’s...

Module/Week 3 ASSIGNMENT (CONTROL STRUCTURES . IF ..ELSE)
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 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.
Submit C++ Programming Assignment 3 by 11:59 p.m. (ET) on Monday of Module/Week 3

Solutions

Expert Solution

Step 1:- In the above problem we can write a c++ program and read value from text file line by line and also used ceil function and give a grade to student and we can make a new text file to store value and grade

Step 2:-

program file:-code

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;

int main()
{
fstream infile("Marks.txt",ios::in);

//read file and check that file is found or not
if(!infile){cerr<<"file could not be found!";exit(1);}

fstream outfile("output.txt",ios::out);
if(!outfile){cerr<<"file could not be created!";exit(1);}

// initialize variable
char fname[20];
char lname[20];
float grades;
int percentage;
char c;
int lines=1;
string grade;
double avg=0;

while(infile.get(c))
{if(c=='\n') lines++;}
infile.clear();
infile.seekg(0);

//visit lines for tale marks

for(int k=0;k<lines;k++)
{

//show student name
infile>>fname;
infile>>lname;
outfile<<fname<<" "<<lname<<" ";
float sum=0;
// red value of 5 subjects
for(int i=0;i<5;i++)
{
if(infile>>grades)
{sum+=grades;
outfile<<grades<<" ";}
  
}
//using ceil function by using cmath
percentage=ceil(sum)/5;
//by using setprecision function we can print value
outfile << fixed << setprecision(5) << sum<<endl;

.//Conditions for show the grade of students
if (percentage >= 90)
{
grade = "Excellent";
}
else
{
if (percentage >= 80 && percentage <= 89)
{
grade = "Well done";
}
else
{
if (percentage >= 70 && percentage <= 79)
{
grade = "good";
}
else
{
if (percentage >= 60 && percentage <= 69)
{
grade = "need improvement";
}
else
{
grade = "Fail";
}
}
}
outfile<<grade;

}
}


system("pause");
return 0;
}

output:-

54.00000

60.60000

Step 3:- Text File:-

Input file

name-> Marks.txt

First_name Last_name Marks1 Marks2 Marks3 Marks4 Marks5 - format

Joker Tom 14 99 26 74 57 mosco tom 67 38 56 95 47 

output file :-

name-> output.txt

Joker Tom 14 99 26 74 57 54.00 Fail

mosco tom 67 38 56 95 47 60.60 need improvement

Summary:- In this above problem we can make a c++ program and full fill all requirement of question. for further query please comment.


Related Solutions

c++ class homework Topics If/Else If statement Description Write a program that determines a student’s final...
c++ class homework Topics If/Else If statement Description Write a program that determines a student’s final grade in the course. The course had three tests (100 points each) and four assignments (also 100 points each). All the test scores make up 70% of the grade and all the assignments 30% of the grade. The program asks the user to input one by one each of the test scores and each of the assignment scores. From these scores, it computes the...
Using C Language Write a program segment that computes 1 + 2 + 3 + ......
Using C Language Write a program segment that computes 1 + 2 + 3 + ... + ( n - 1) + n , where n is a data value. Follow the loop body with an if statement that compares this value to (n * (n + 1)) / 2 and displays a message that indicates whether the values are the same or different. Please give me code to just copy and paste
write pseudocode not c program If- else programming exercises 1.    Write a C program to find...
write pseudocode not c program If- else programming exercises 1.    Write a C program to find maximum between two numbers. 2.    Write a C program to find maximum between three numbers. 3.    Write a C program to check whether a number is negative, positive or zero. 4.    Write a C program to check whether a number is divisible by 5 and 11 or not. 5.    Write a C program to check whether a number is even or odd. 6.    Write...
Write a program in C that computes the area of a circle (Area = pi *...
Write a program in C that computes the area of a circle (Area = pi * r2) and the volume of a sphere (Volume = 4/3 * pi * r3). Both formulas use r which is the radius. Declare a float variable pi = 3.14159. Get the value of r from the keyboard and store it in a float variable. Display both the area of the circle and the volume of the sphere.
In the space provided below write a C ++ program that computes the total amount of...
In the space provided below write a C ++ program that computes the total amount of money you are depositing in your bank account. Your program does this by asking you to first enter the number and amount of each check you are depositing, and then it asks you to enter the type of cash bills being deposited and how many of each type, also the types of coins being deposited, and the number of each coin type.
Write a C++ program that inputs a sequence of integers into a vector, computes the average,...
Write a C++ program that inputs a sequence of integers into a vector, computes the average, and then outputs the # of input values, the average, and the values themselves. There are 0 or more inputs values, followed by a negative value as the sentinel; the negative value is not stored and not counted. The following sample input: 10 20 0 99 -1 would produce the following output: N: 4 Avg: 32.25 10 20 0 99 The main program has...
Write a C++ program that inputs a sequence of integers into a vector, computes the average,...
Write a C++ program that inputs a sequence of integers into a vector, computes the average, and then outputs the # of input values, the average, and the values themselves. There are 0 or more inputs values, followed by a negative value as the sentinel; the negative value is not stored and not counted. The following sample input: 10 20 0 99 -1 would produce the following output: N: 4 Avg: 32.25 10 20 0 99 The main program has...
1.Write a C++ program using control structures, arrays, functions to calculate the number of dollars, quarters,...
1.Write a C++ program using control structures, arrays, functions to calculate the number of dollars, quarters, dimes, nickels, and pennies in a given amount of money. The input should be a floating-point value representing a decimal value. Example: 63.87 à 63 [dollars and 87 cents] should output 63 dollars, 3 quarters, 1 dime, 0 nickels, and 2 pennies. 2. In trigonometry the cosine function can be calculated using cos(x) = 1 – x 2 /2! + x 4 /4!- x...
Write a program that asks the user to enter 3 grades and computes the minimum and...
Write a program that asks the user to enter 3 grades and computes the minimum and the maximum of those 3 grades and prints it. Hint: Use the Math.min() and Math.max() methods. This program will compute the smallest and highest of 3 grades entered by the user. Enter 3 grades separated by a space: 100 85.3 90.5 Smallest: 85.3 Highest: 100.0 Bye
In the space provided below write a C++ program that computes the total cost of books...
In the space provided below write a C++ program that computes the total cost of books you want to order from an online bookstore. It does so by first asking how many books are in your shopping cart and then based on that number, it repeatedly asks you to enter the cost of each item. It then calls two functions: one for computing the taxes and another for computing the delivery charges. The function which computes delivery charges works as...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT