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...
Based on your project scenario that has been suggested by you or by your instructor and...
Based on your project scenario that has been suggested by you or by your instructor and approved by your instructor, answer the following questions. Project Title: Scenario Overview: Q1 In one page, create the project charter. Create the project scope statement. Q2 Using any project management tool, Identify the project milestones and draw Gantt chart. Draw AOA network diagram. Identify all paths including the critical path for the project. In one page, create the Lessons-Learned report.
TCP Wireshark Lab – Working with a remote server.  You will go through the steps below, use...
TCP Wireshark Lab – Working with a remote server.  You will go through the steps below, use your captured wireshark file and the provided wireshark file (on D2L) to answer the questions.  When you have finished the lab you will submit the following: This document with your answers provided in the appropriate places.   Your wireshark capture file as a zipped file.   STEPS: 1. Start up your web browser. Go thehttp://gaia.cs.umass.edu/wireshark-labs/alice.txtand retrieve an ASCII copy of Alice in Wonderland. Store this file somewhere...
You are considering a project that will cost $50,000 to set up, and will pay out...
You are considering a project that will cost $50,000 to set up, and will pay out $18,000 1, 2, 3 and 4 years from today. The unlevered beta for this project is 1.2, the risk free rate is 6.5%, and the expected return on the S&P 500 is 15%. Corporate taxes are 25%. a. What is the unlevered cost of equity for this project? b. What is the NPV of this project if you finance with all equity? c. You...
Microsoft: 1. In the lab, you set auditing for logon for success and failure, in your...
Microsoft: 1. In the lab, you set auditing for logon for success and failure, in your own words, why is it important to capture both types of events? 2. What did you learn about Installing and configuring the LAPS tool?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT