1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
snow_lady [41]
3 years ago
12

Exercise 4: Bring in program grades.cpp and grades.txt from the Lab 10 folder. Fill in the code in bold so that the data is prop

erly read from grades.txt. and the desired output to the screen is as follows: OUTPUT TO SCREEN DATAFILE Adara Starr has a(n) 94 average Adara Starr 94 David Starr has a(n) 91 average David Starr 91 Sophia Starr has a(n) 94 average Sophia Starr 94 Maria Starr has a(n) 91 average Maria Starr 91 Danielle DeFino has a(n) 94 average Danielle DeFino 94 Dominic DeFino has a(n) 98 average Dominic DeFino 98 McKenna DeFino has a(n) 92 average McKenna DeFino 92 Taylor McIntire has a(n) 99 average Taylor McIntire 99 Torrie McIntire has a(n) 91 average Torrie McIntire 91 Emily Garrett has a(n) 97 average Emily Garrett 97 Lauren Garrett has a(n) 92 average Lauren Garrett 92 Marlene Starr has a(n) 83 average Marlene Starr 83 Donald DeFino has a(n) 73 average Donald DeFino 73

Computers and Technology
1 answer:
Alex73 [517]3 years ago
3 0

Answer:

Here is the C++ program:

#include <fstream>  //to create, write and read a file

#include <iostream>  // to use input output functions

using namespace std;  //to access objects like cin cout

const int MAXNAME = 20;  //MAXNAME is set to 20 as a constant

int main(){  //start of main() function

ifstream inData;  //creates an object of ifstream class

inData.open("grades.txt");  //uses that object to access and opens the text file using open() method

char name[MAXNAME + 1];   // holds the names

float average;   //stores the average

inData.get(name,MAXNAME+1);  //Extracts names characters from the file and stores them as a c-string until MAXNAME+1 characters have been extracted

while (inData){  //iterates through the file

 inData >> average;  //reads averages from file using the stream extraction operator

 cout << name << " has a(n) " << average << " average." << endl; //prints the names along with their averages

 inData.ignore(50,'\n');  //ignores 50 characters and resumes when  new line character is reached. It is used to clear characters from input buffer

 inData.get(name,MAXNAME+1);}  //keeps extracting names from file

return 0; }

Explanation:  

The program is well explained in the comments added to each line of the code. The program uses fstream object inData to access the grades.txt file. It gets and extracts the contents of the file using get() method, reads and extracts averages from file using the stream extraction operator. Then program displays the names along with their averages from grades.txt on output screen.

The grades.txt file, program and its output is attached.

You might be interested in
Consider the following code snippet:public static void main(String[] args) throws FileNotFoundExceptionWhich of the following st
iVinArrow [24]

Answer:

The main method should simply terminate if the FileNotFoundException occurs.

Explanation:

Considering the full code snippet

snippet:public static void main(String[] args) throws FileNotFoundException

public static void main(String[])

represent the entry point method to a java main method

The addition of

throws FileNotFoundException

widens the scope of the main method to explicitly specifies that an exception named the FileNotFoundException may be thrown.

So, if any part of the code explicitly throws the FileNotFoundException the compiler makes use of this to throw an exception.

By throwing an exception, the main method is not catching any exceptions, instead it handles the FileNotFoundException by throwing it to the source which invoked the main method

This is required by the compiler to terminate the program if the FileNotFoundException occurs.

8 0
3 years ago
Which of the following code displays the area of a circle if the radius is positive? Question 4 options: if (radius &lt;= 0) Sys
Marina CMI [18]

Answer:

(d) if (radius > 0) System.out.println(radius * radius * 3.14159);

Explanation:

Given

Code segment (a) to (d)

Required

Which is correct

Code segment (a): radius <=0

This means that radius is 0 or less, i.e. 0 or negative

Code segment (b): radius !=0

This means that radius is not equal to 0 i.e. it could be positive or negative but definitely not 0

Code segment (c): radius >=0

This means that radius is 0 or greater, i.e. 0 or positive

Code segment (d): radius >0

This means that radius is  greater than 0 i.e. positive

<em>Hence, (d) is correct</em>

3 0
3 years ago
Why do we need the binary system?
nika2105 [10]

Answer:

We need to have binary numbers because that is how computers process data.

Explanation:

6 0
3 years ago
A user creates a GPO. What do you need to do for that user to manage his or her GPO that he or she created?
d1i1m1o1n [39]

Answer: Nothing should be done.

Explanation:

Group Policy helps in the provision of a centralized management of operating systems, and applications. It should be noted that a group policy object (GPO) is simply referred to as the configurations involving the group policy.

Nothing should be done to manage the GPO created. When the permission to create a GPO has been given to someone, it means that they can also manage the GPO therefore, nothing needs to be done anymore.

8 0
2 years ago
Select the correct answer. Which is an example of noisy data in data sources? A. Age: 987 B. Gender: Male C. First Name: Gary D.
umka21 [38]

Answer:

A. Age 987 is the noisy data

Explanation:

Undoubtedly, this one is, as it is going to create a buzz in each person ear, who is going to listen it.  This age is almost impossible. However, some Monks from Tibet have been able to live for so long however! And this makes my answer a noisy data, as many will not believe on first read. Something which is rare, is the noisy data. And when it is proved and accepted, it becomes a noisy information.

7 0
3 years ago
Other questions:
  • When looking through the documentation for a specific class, you never actually see the source code for that class. Instead, you
    6·1 answer
  • Which of the following terms describes surgery through a small incision in the abdomen?
    11·1 answer
  • What symbol do you use to choose a feature for your notes on Notion?
    8·1 answer
  • Examine the following algorithm.
    9·1 answer
  • Tim is in charge of the upcoming interschool baketball tournamnent. He wants to arrange all of the teams and their members in al
    11·1 answer
  • When is 1600 plus 25 and 1700 minus 35 the same thing?​
    10·1 answer
  • Binary is best interpreted by a computer because ​
    12·2 answers
  • This is a glitch ? 


 










































    14·1 answer
  • How to implement switch statement in Python?
    11·2 answers
  • Why do you want to work for Rev?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!