how can i make average/maximum/minimum score to an output file?

This is a discussion on how can i make average/maximum/minimum score to an output file? within the C++ Programming forums, part of the General Programming Boards category; i have to make a score average, minimum, maximum as statistics for the out file. here is the code i ...

  1. #1
    Registered User
    Join Date
    Nov 2013
    Posts
    12

    how can i make average/maximum/minimum score to an output file?

    i have to make a score average, minimum, maximum as statistics for the out file. here is the code i have done:

    Code:
    #include "stdafx.h"
    #include <iostream>
    #include <string>
    #include <fstream>
    #include <assert.h>
    
    
    using namespace std;
    
    
    int openfiles(ifstream& infile, ofstream& outfile);
    
    
    void Size(ofstream&, int, string);
    
    
    int main()
    {
    	int num_student = 4, count, length, score2, w[6];
    
    
    	ifstream infile, curvingfile; char x;
    
    
    	ofstream outfile; float score;
    
    
    	string  key, answer, id;
    
    
    	do {
    		openfiles(infile, outfile);  // function calling
    
    
    		infile >> key; // answer key
    
    
    		for (int i = 0; i < num_student; i++) // loop over each student
    
    
    		{
    			infile >> id;
    
    
    			infile >> answer;
    
    
    			count = 0;
    
    
    			length = key.size(); // length represents number of questions in exam from exam1.dat
    								 // size is a string function....
    			
    			Size (outfile, length, answer);
    
    
    			for (int j = 0; j < length; j++) // loop over each question
    			{
    				if (key[j] == answer[j])
    
    
    					count++;
    			}
    
    
    			score = (float) count / length; 
    
    
    			score2 = (int)(score * 100);
    
    
    			outfile << id << "     " << score2 << "%";
    
    
    			if (score2 >= 90)//<-----w[0]
    
    
    				outfile << "A" << endl;
    
    
    			else if (score2 >= 80)//<-----w[1]
    
    
    				outfile << "B" << endl;
    
    
    			else if (score2 >= 70)//<-----w[2]
    
    
    				outfile << "C" << endl;
    
    
    			else if (score2 >= 60)//<-----w[3]
    
    
    				outfile << "D" << endl;
    
    
    			else if (score2 >= 50)//<-----w[4]
    
    
    				outfile << "E" << endl;
    
    
    			else if (score2 < 50)//<-----w[5]
    
    
    				outfile << "F" << endl;
    		}
    		cout << "Would you like to attempt a new trial? (y/n): ";
    
    
    		cin >> x;
    	
    	} while (x == 'y' || x == 'Y');
    
    
    	return 0;
    }
    
    
    int openfiles(ifstream& infile, ofstream& outfile)
    {
    	string name1, name2, name3, answerstring, curvedata;
    
    
    	cin >> name1; name2; name3;
    	if (name1 == "exit" || name2 == "exit" || name3 == "exit" ) return false;
    	 
    	cout << "Input the name for the exam file: ";
    
    
    	cin >> name1;
    
    
    	infile.open(name1.c_str());
    
    
    	infile >> answerstring;
    
    
    	cout << "Input the name for the curving file: ";
    
    
    	cin >> name2;
    
    
    	infile.open(name2.c_str());
    
    
    	infile >> curvedata;
    
    
    	cout << "Input the name for the output: ";
    
    
    	cin >> name3;
    
    
    	outfile.open(name3.c_str());
    
    
    	return true;
    }
    
    
    void Size(ofstream& outfile, int length, string answer)
    
    
    {
    	bool check;// extra answers, lesser answers...
    
    
    	if (answer.size() > length)
    
    
    	{
    		outfile << "Unnecessary extra answers";
    	}
    
    
    	else if (answer.size() < length)
    
    
    	{
    		outfile << "The remaining answers are incorrect";
    	}
    
    
    	else { check = false; };
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,344
    You already have an open thread.
    need help as a c++ beginner; just a few questions with code and everything in here!

    It's also clear that you're not really paying any attention.
    Your openfiles() is as broken as it ever was.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Invalid Output of Minimum and Maximum Value in Array
    By georgio777 in forum C Programming
    Replies: 10
    Last Post: 09-19-2009, 03:17 AM
  2. Replies: 2
    Last Post: 05-28-2009, 09:58 PM
  3. maximum and minimum
    By aslak in forum C Programming
    Replies: 35
    Last Post: 12-14-2008, 02:54 PM
  4. Maximum and Minimum Values
    By swaugh in forum C Programming
    Replies: 7
    Last Post: 12-16-2006, 08:43 PM
  5. Maximum And Minimum
    By drdodirty2002 in forum C++ Programming
    Replies: 2
    Last Post: 10-19-2004, 12:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21