Question

In: Computer Science

Your lab instructor will guide you through the steps necessary to set up this project in...

Your lab instructor will guide you through the steps necessary to set up this project in Visual Studio. Video instructions for people using other programs can be found here: XCode, Code::Blocks and repl.it.

  • Using the lab samples as a starting point, write a program called lab4.cpp to input 10 float values from an input file input.txt.
    (Hint, you have to create the input.txt file yourself)
  • Output the sum and the average of the 10 float values to an output file output.txt.
  • Be sure to test to see if you opened the input and output files before you use them.
  • Compile and run this C++ program.
  • Run the program for your lab instructor and show the result in output.txt.

Solutions

Expert Solution

Given below is the code for the question. Please copy input.txt also. The program creates output.txt..
Please do rate the answer if it helped. Thank you.

input.txt
--------
14.1 58.7 14.1 52.9 39.0
54.1 79.0 69.0 99.1 29.1


main.cpp
-------
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
   ifstream infile("input.txt");
   float sum = 0, avg = 0, num;
   int n = 0;
  
  
   if(!infile){
       cout << "Error: Could not open input.txt" << endl;
       return 0;
   }
  
   while(infile >> num){
       sum += num;
       n++;
   }
   infile.close();
  
   avg = sum / n;
  
  
   ofstream outfile("output.txt");
   outfile << "Sum = " << sum << endl;
   outfile << "Average = " << avg << endl;
   outfile.close();
  
   cout << "output.txt created" << endl;
   return 0;
}

output.txt
==========
Sum = 509.1
Average = 50.91


Related Solutions

​In preparation for your final assignment you will be preparing the documents necessary to set up...
​In preparation for your final assignment you will be preparing the documents necessary to set up a corporation and will also discussing the advantages and disadvantages of the three most common types of business entities. ​The first step is to go to the Virginia State Corporation commission website and download the applicable forms for creation of a corporation in Virginia. Two then to fill out those forms as if you were preparing an actual Corporation. These forms will be submitted...
Carefully work through the sample calculations for this lab ON PAPER. Then, set up the same...
Carefully work through the sample calculations for this lab ON PAPER. Then, set up the same equations on a separate sheet of paper, but replace the values in the ‘Sample Calculations’ folder with the ones provided below and complete the calculations: Mass of Zinc = 0.0928 g H2 volume reading from the eudiometer tube = 35.98 mL Water bath temperature = 19.9 °C Barometric pressure = 768.2 mm Hg Level (pressure) difference from the meter stick = 41.20 cm H2O...
PROCEDURE: Your instructor will demonstrate how to set up, calibrate, and use a pH meter. Be...
PROCEDURE: Your instructor will demonstrate how to set up, calibrate, and use a pH meter. Be sure to observe the following precautions when using the pH meter.    1. The glass electrode is rather fragile and expensive. It can be broken easily, or it can be scratched. Be very careful when handling it that no hard object hits or even rubs against the tip of this electrode. Glass electrodes are frequently protected with a plastic shield. Do not try to...
Instead of following the incubation directions listed in your lab protocol, imagine that you set up...
Instead of following the incubation directions listed in your lab protocol, imagine that you set up your plates and then left them incubating for over a week before you looked again at them.  What problems could this cause for your MSA plates?  How about for your EMB and MacConkey plates?
As a lab instructor in machining, you are required to prepare a lab module for a...
As a lab instructor in machining, you are required to prepare a lab module for a laboratory session with your students. In this session, the students are required to produce aT-Slot. Prepare the methodology to produce the T -Slot with illustrations for the lab module.
ACC 121 Project (Use the working papers provided by your instructor to work this practice set...
ACC 121 Project (Use the working papers provided by your instructor to work this practice set project.) Colorado Company uses a perpetual inventory system and both an accounts receivable and an accounts payable subsidiary ledger. Balances related to both the general ledger and the subsidiary ledger for Colorado Co. are indicated in the working papers. Below are a series of transactions for the company for the month of January. Credit sales terms are 2/10, n/30. The cost of all merchandise...
Identify the process you would set up to evaluate at least one capital project that you...
Identify the process you would set up to evaluate at least one capital project that you as a healthcare manager would submit to your finance department during the capital request process for your organization. This assignment is a maximum 3 page paper that identifies the process you would go through to develop and present your capital project request. Include all the steps you would take into consideration so you could submit these projects to be considered by your organization. Also,...
Is it necessary for every research project to have a set of hypotheses? Why or why...
Is it necessary for every research project to have a set of hypotheses? Why or why not? What is the role of the researcher in the problem definition process? How may a marketing researcher be creative in interpreting a research brief and developing a research proposal? What is the significance of the ‘background’ section of a research brief and research proposal? Describe some of the reasons why management is often not clear about the ‘real’ problem they face. What interrelated...
In her will, your aunt set up a trust that is required to pay you the...
In her will, your aunt set up a trust that is required to pay you the sum of $5,000 a year forever with payments starting immediately. However, the news is better. She has specified that this $5,000 should grow at 5% per year. Given an interest rate of 12%, what is the PV of the inheritance? Please include formulas used. Thanks
(IN YOUR WORDS) set up questionnaire You are considering to hire a few employees for your...
(IN YOUR WORDS) set up questionnaire You are considering to hire a few employees for your educational company. You should think about the profile of employees you are looking for and how many precisely for which position. In order to make the best of your employees, you need to come up with a questionnaire which will reflect your company needs and vision, as well as commitment the employee needs to show in order to be hired by your company. Instructions:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT