Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3273864
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:58:37+00:00 2026-05-17T18:58:37+00:00

New code…. #include <cstdlib> #include <iostream> #include <fstream> #include <iomanip> using namespace std; void

  • 0

New code….

#include <cstdlib>
#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

void gradeg (double & average, string & grade)
{
    if (average >= 90)
        {
            grade = "A";
        }
        else if ((average < 90) & (average >= 80))
        {
            grade = "B";
        }
        else if ((average < 80) & (average >= 70))
        {
            grade = "C";
        }
        else if ((average < 70) & (average >= 60))
        {
            grade = "D";
        }
        else
        {
            grade = "F";
        }
}

void totalg (int & total, int & s1, int & s2, int & s3)
{
    total=(s1+s2+s3);
}

void averageg (double & average, int & total)
{
    average=total/3.0;
}

int main()
{
    ifstream fin;
    ofstream fout;

    fout.setf (ios::fixed);
    fout.setf (ios::showpoint);
    fout.precision (2);

    char filename[15];

    fin.open("input.txt");

    cout << "Please enter the name of your output file: ";
    cin >> filename;

    fout.open(filename);

    if (fin.fail())
    {
        cout << "Failed to open INPUT file." << endl;
        exit(1);
    }
    if (fout.fail())
    {
        cout << "Failed to open OUTPUT file." << endl;
        exit(1);
    }

    string grade, name;
    int s1, s2, s3, total=0;
    double average=0.0;


    fout << left << "Names" << setw(24) << "Score 1" << setw(10) << "Score 2" << setw(10) << "Score 3" << setw(10) << "Total" << setw(10) << "Average"<< setw(10) << "Grade \n";

    cout << "Reading from input files.....";

    while (! fin.eof())
    {
        fin >> name >> s1 >> s2 >> s3;

        totalg (total, s1, s2, s3);

        averageg (average, total);

        gradeg (average, grade);


        fout << left << name << setw(24) << s1 << setw(10) << s2 << setw(10) << s3 << setw(10) <<total << setw(10) << average << setw(10) << grade << "\n";

    }

    cout << "Your output file has been created and the computation results have been stored.";

    return 0;
}

New output…

NamesScore 1                 Score 2   Score 3   Total     Average   Grade 
   DAN100                     70        85        255       85.00     B         
JANE78                      82        90        250       83.33     B         
PETER82                      84        91        257       85.67     B         
MINIE98                      100       75        273       91.00     A         
JOSEPH71                      62        100       233       77.67     C         
CHRISTOPHER91                      75        82        248       82.67     B         
BEN54                      84        77        215       71.67     C         
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T18:58:37+00:00Added an answer on May 17, 2026 at 6:58 pm

    You’re making a very simple mistake, which is that a formatting manipulator (such as setw) has to come before the data that it formats, like so:

    fout << left << setw(24) << "Names" << setw(10) << "Score 1" << setw(10) << "Score 2" << setw(10) << "Score 3" << setw(10) << "Total" << setw(10) << "Average"<< setw(10) << "Grade \n";
    fout << left << setw(24) << name << setw(10) << s1 << setw(10) << s2 << setw(10) << s3 << setw(10) <<total << setw(10) << average << setw(10) << grade << "\n";
    //              ^^^^^^^^^^^ NOTE THIS PART
    

    The word Names will take up 5 characters, and it will be followed by 19 spaces. Following that, you’ll see Score 1 (7 characters) followed by 3 spaces, and so forth.

    Names                   Score 1   Score 2   
    Ken Bloom               75        100       
    Alec                    100       75        
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Typically when writing new code you discover that you are missing a #include because
In new C++ code, I tend to use the C++ iostream library instead of
I am writing some new code that will throw a custom exception - I
I need to optimize code to get room for some new code. I do
There are times when I want to test new code from the forums or
Given the code: new Thread(new BackgroundWorker()).start(); Intuitively it feels like the BackgroundWorker instance should
I rewrite my old code in new style, like below: #old style open(FD,file); #new
Is it possible to actually make use of placement new in portable code when
I have the following code: $bind = new COM(LDAP://CN=GroupName,OU=Groups,OU=Division,DC=company,DC=local); When I execute it from
I have have some code which adds new cells to a table and fills

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.