Question

The Percentage ProblemBACKGROUND: If youve followed lecture, you already know almost everything there is about arrays. Now you need some practice!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Thanks for the question.


Below is the simple code you will be needing.

Note : When you run the program in your pc, please update the file's path location of the exam.dat file in the below line -

char *filename="F:\\exam.dat";


Thank You !!


===========================================================================

#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;


const int MAX=25;

int main(){
  
   char *filename="F:\\exam.dat";
   int numbers[MAX];
   ifstream infile(filename);
  
   int count=0;
   int total=0;
   int number;
   if(infile.is_open()){
       while (infile>>number && count <MAX){
           total+=number;
           numbers[count++]=number;
       }
       infile.close();
      
       cout<<setw(10)<<left<<"Sum Equals:"<<setw(7)<<right<<total<<endl;
       cout<<endl;
      
       for(int i=0; i<count;i++){
          
           cout<<setw(10)<<right<<numbers[i]
               <<setw(7)<<fixed<<setprecision(1)
               <<100.0*numbers[i]/total<<"%"<<endl;
       }
      
      
      
   }else{
       cout<<"ERROR: Unable to read data from file: "<<filename<<endl;
   }
}

:: :: ~ * TDM-GCC 4.9.2 64-bit Release v jau Eile Edit Search View OO Project Classes Debug Projects Project Execute Tools AS

Add a comment
Know the answer?
Add Answer to:
The Percentage Problem BACKGROUND: If you've followed lecture, you already know almost everything there is about...
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
  • OLA203 Exercise Due (by midnight): February 13, 2020 NOTE: Please remember that exercises are due by...

    OLA203 Exercise Due (by midnight): February 13, 2020 NOTE: Please remember that exercises are due by the stated time and cannot be late. OBJECTIVE: Practice using CodeLite and C++, especially functions, if statements, while loops, and opening/closing files. Again, this solo assignment should help you honestly assess your programming skill level and personal understanding of C++. PROBLEM BACKGROUND: An integer N (greater than or equal to 2) is prime if and only if the only integer larger than 1 that...

  • For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java...

    For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java program that will input a file of sentences and output a report showing the tokens and shingles (defined below) for each sentence. Templates are provided below for implementing the program as two separate files: a test driver class containing the main() method, and a sentence utilities class that computes the tokens and shingles, and reports their values. The test driver template already implements accepting...

  • 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...

  • //I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which...

    //I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which manipulates text from an input file using the string library. Your program will accept command line arguments for the input and output file names as well as a list of blacklisted words. There are two major features in this programming: 1. Given an input file with text and a list of words, find and replace every use of these blacklisted words with the string...

  • Write a C program as follows: Single source code file Calls a function with an arbitrary...

    Write a C program as follows: Single source code file Calls a function with an arbitrary name (i.e. you name it) that accepts two arrays of the same size The function should add each element in the arrays together and place the values in a third array Each array element, each array address, and the sum are printed to the screen in tabulated format with headersI also would like to request that LOTS of comments be included, as I need...

  • programing C,already write part of code (a) Write a function print.array that receives an array of...

    programing C,already write part of code (a) Write a function print.array that receives an array of real numbers and the number of el stored in the array. This function must display the elements of the array in order with each one on a line by itself in a field width of 7 with two decimal places. (See sample output. Recall the format specifier would be "%7.21f"). (b) Sometimes we want to treat an array as a mathematical vector and compute...

  • Banks issue credit cards with 16 digit numbers. If you've never thought about it before you...

    Banks issue credit cards with 16 digit numbers. If you've never thought about it before you may not realize it, but there are specific rules for what those numbers can be. For example, the first few digits of the number tell you what kind of card it is - all Visa cards start with 4, MasterCard numbers start with 51 through 55, American Express starts with 34 or 37, etc. Automated systems can use this number to tell which company...

  • please I need help with the question: Problem: Write a C++ program that reads each character...

    please I need help with the question: Problem: Write a C++ program that reads each character from a user input, extracts the character if it is a digit, and calculates the sum of all the digits. The program stops reading the user input when the new line character ‘\n’ is encountered. For the output of the program, you should print each digit extracted from the user input and the sum of all the digits. (*The main difference between “cin >>...

  • C++ requirements The store number must be of type unsigned int. The sales value must be...

    C++ requirements The store number must be of type unsigned int. The sales value must be of of type long long int. Your program must properly check for end of file. See the section Reading in files below and also see your Gaddis text book for details on reading in file and checking for end of file. Your program must properly open and close all files. Failure to follow the C++ requirements could reduce the points received from passing the...

  • Need this in C The starter code is long, if you know how to do it...

    Need this in C The starter code is long, if you know how to do it in other way please do. Do the best you can please. Here's the starter code: // ----------------------------------------------------------------------- // monsterdb.c // ----------------------------------------------------------------------- #include #include #include // ----------------------------------------------------------------------- // Some defines #define NAME_MAX 64 #define BUFFER_MAX 256 // ----------------------------------------------------------------------- // Structs typedef struct { char name[NAME_MAX]; int hp; int attackPower; int armor; } Character; typedef struct { int size; Character *list; } CharacterContainer; // ----------------------------------------------------------------------- //...

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