Question

PLEASE USE BASIC C++ CODE

PLEASE USE BASIC C++ CODE

PLEASE HAVE DONE AS SOON AS POSSIBLE

THANK YOU I REALLY APPRECIATE IT

Same program as Quiz #4, but this time it must be done with arrays: Write a program that calculates the average of 5 test sco

FILE TEXT:

Mary 80 90 75 90 85
Joe 80 65 80 80 80

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

/*
 *  C++ Program for file reading average grade print
 */

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
#define MAX_STUD 50
#define MAX_SUB 5

struct student {
  string name;
  int scores[MAX_SUB];
};

//  first function
void readFileToArray(string fileName, student studentArray[], int &size)
{
  fstream file;
  file.open(fileName.c_str(), ios :: in);
  
  int i = 0, sumTemp = 0;

  while (!file.eof())
  {
    sumTemp = 0;
    file >> studentArray[i].name;
    for (int j = 0; j < MAX_SUB; j++)
    {
      file >> studentArray[i].scores[j];
    }
    i += 1;
  }
  
  file.close();
  size = i;
}

//  second function
double getAvgScore(int scores[])
{
  double sumTemp = 0;
  for (int i = 0; i < MAX_SUB; i++)
  {
    sumTemp += scores[i];
  }
  return (double)sumTemp/MAX_SUB;
}

int main()
{
  student studentArray[MAX_STUD];
  string fileName = "file.txt";
  int i = 0, N;

  readFileToArray(fileName, studentArray, N);

  for (i = 0; i < N; i++)
  {
    cout << studentArray[i].name << " average is: " << getAvgScore(studentArray[i].scores) << endl;
  }

  return 0;
}

> clang++-7 -pthread -std=c++17 -o main main.cp р 3./main Jones average is: 84 Joe average is: 77 1 /* 2 C++ Program for file

file.txt 1 2 Mary 80 90 75 90 85 Joe 80 65 80 80 80

Note: For queries, drop me a comment.

Add a comment
Know the answer?
Add Answer to:
PLEASE USE BASIC C++ CODE PLEASE USE BASIC C++ CODE PLEASE HAVE DONE AS SOON AS...
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
  • Please help me with this program.You are to write a C++ program that will read in...

    Please help me with this program.You are to write a C++ program that will read in up to 15 students with student information and grades. Your program will compute an average and print out certain reports. Format: The information for each student is on separate lines of input. The first data will be the student�s ID number, next line is the students name, next the students classification, and the last line are the 10 grades where the last grade is...

  • PLEASE SOLVE USING BASIC C++ CODEING PRINCIPLES PLEASE USE BASIC ARRAY, FUNCTION, AND LOOPING PRINCIPLES PLEASE...

    PLEASE SOLVE USING BASIC C++ CODEING PRINCIPLES PLEASE USE BASIC ARRAY, FUNCTION, AND LOOPING PRINCIPLES PLEASE COMPLETE ALL ASPECTS OF PAPER THANK YOU!!! Objectives To learn to code, compile and run a program containing ARRAYS. . Assignment Plan and code a modular program utilizing arrays. Use at least three functions to solve the problem. Input numbers from a textfile. Input the numbers, one by one. Store the even numbers in one array. Store the odd numbers in a second array....

  • USE C++ FOR THE CODE THAT CAN RUN IN VISUAL STUDIO 2019 (or a complier) Ignore...

    USE C++ FOR THE CODE THAT CAN RUN IN VISUAL STUDIO 2019 (or a complier) Ignore the last paragraph on the bottom of the page! \ Write a program YourName-Assignments (replace Your Name with your actual name, no spaces) that reads from students' records (one student per line) in the following format: Last Name Tests Grade Assignments Grade and computes and outputs (to the console) the STUDENT STATISTICS in a table format one line per student: Student Name Total Points...

  • C++ please make it sifferent and unique Description Write a program that will read data from...

    C++ please make it sifferent and unique Description Write a program that will read data from the file "p6.dat". The file (that you will create) always contains 15 test scores (whole numbers between O and 100). The test scores are scores for 5 students taking 3 tests, and are arranged, in the file, by the student - that is the first 3 numbers are the test scores for test 1, 2, and 3 for the first student, etc. The program...

  • A set of data (test scores), can be summarized by a frequency distribution chart. For example,...

    A set of data (test scores), can be summarized by a frequency distribution chart. For example, if the list of test scores is: 90 85 100 50 50 85 60 70 55 55 80 95 70 60 95 80 100 75 70 95 90 90 70 95 50 65 85 95 100 65 then the frequency distribution chart looks like the one below: value           frequency ------           ------------ 100                3           95          ...

  • Using C++. Please Provide 4 Test Cases. Test # Valid / Invalid Data Description of test...

    Using C++. Please Provide 4 Test Cases. Test # Valid / Invalid Data Description of test Input Value Actual Output Test Pass / Fail 1 Valid Pass 2 Valid Pass 3 Valid Pass 4 Valid Pass Question 2 Consider a file with the following student information: John Smith 99 Sarah Johnson 85 Jim Robinson 70 Mary Anderson 100 Michael Jackson 92 Each line in the file contains the first name, last name, and test score of a student. Write a...

  • //Done in C please! //Any help appreciated! Write two programs to write and read from file...

    //Done in C please! //Any help appreciated! Write two programs to write and read from file the age and first and last names of people. The programs should work as follows: 1. The first program reads strings containing first and last names and saves them in a text file (this should be done with the fprintf function). The program should take the name of the file as a command line argument. The loop ends when the user enters 0, the...

  • Write a program that uses pointer notation to dynamically allocate parallel array(s) large enough to hold...

    Write a program that uses pointer notation to dynamically allocate parallel array(s) large enough to hold a user-defined number of test scores and student names, using parallel arrays. After student names and corresponding scores are entered, the array(s) should be passed to a function that sorts them in ascending order. Another function should be called that calculates the average score for the group (do not include the lowest score in the calculation of average grade). The program should display the...

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

  • C++ program that reads students' names followed by their test scores (5 scores) from the given...

    C++ program that reads students' names followed by their test scores (5 scores) from the given input file, students.txt. The program should output to a file, output.txt, each student's first name, last name, followed by the test scores and the relevant grade. All data should be separated by a single space. Student data should be stored in a struct variable of type StudentType, which has four components: studentFName and studentLName of type string, an array of testScores of type int...

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