Question

Write a program based on 8_lb that reads in the inC++

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

#include<iostream>
#include<fstream>
#include<vector>

int main()
{
char filename[20];
vector<int> vec;
vector<int> vec2;
int total=0;
  
cout << "Enter file name with extension ";
cin >> filename;
std::ifstream myfile(filename);
std::ofstream outfile("output.txt");
  
int a,i;
do
{
myfile >> a;   
vec.push_back(a);
} while(!myfile.eof());
  
cout << "Writing original vector to file \n";
outfile << "Original Vector\n";
  
for(i = 0; i < vec.size(); i++){
   cout <<i;
cout << "value of vec [" << i << "] = " << vec[i] << endl;
outfile << vec[i]<<"\n";
}
for( i = 0; i < vec.size(); i++){
vec2.push_back(vec[i]*10);
}
cout << "Writing 10x vector to file \n";
outfile << "10x Vector\n";
  
for( i = 0; i < vec2.size(); i++){
cout << "value of vec [" << i << "] = " << vec2[i] << endl;
total=total+vec2[i];
outfile << vec2[i]<<"\n";
}
outfile <<"\nTotal of 10x vector is "<<total<<"\n";
      

}

Add a comment
Know the answer?
Add Answer to:
C++ Write a program based on 8_lb that reads in the integer data from "input.txt" into...
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
  • 1. use c++ write a c++ program that reads 10 integers from a file named input.txt...

    1. use c++ write a c++ program that reads 10 integers from a file named input.txt in this file the 10 integers wil be on a single line with space between the. calculate the average of these numbers and then write his number to a file named output.txt. if the program is unable to successfully complete the file operations then display eero message to the console.

  • How to write a Java program that reads the file "input.txt" and writes all even values...

    How to write a Java program that reads the file "input.txt" and writes all even values from this file into a new file called "output.txt." Sample input 10 12 1 3 5 34 2 5 7 9 44

  • write a program in c ++ that reads the length and width of a rectangle from...

    write a program in c ++ that reads the length and width of a rectangle from a file named input.txt and write the area and perimeter of the rectactangle to file named output.txt

  • Write a program in C that reads 20 float numbers from a file. The values are...

    Write a program in C that reads 20 float numbers from a file. The values are stored in a vector (1-dimensional array). Find and display the smallest number, the second smallest number, and the third smallest number of the set. Use only these libraries: stdio.h, stdlib.h, math.h, and string.h. Below is an example of the input file (in1.txt) and the resulting output file (output.txt). In1.txt: 3.14       4.05       -3.73      4.13       1.32 -2.21      0.46       4.57       4.64       -3.42 4.57       -0.14      3.00       -3.58      -0.78...

  • Write a C program that reads a list of positive integers from a file named "input.txt."...

    Write a C program that reads a list of positive integers from a file named "input.txt." and count number of odd integers and even integers and prints the results to another file called "results.txt". Please submit both the input and results files along with the c program.

  • Description: Create a program called numstat.py that reads a series of integer numbers from a file...

    Description: Create a program called numstat.py that reads a series of integer numbers from a file and determines and displays the name of file, sum of numbers, count of numbers, average of numbers, maximum value, minimum value, and range of values. Purpose: The purpose of this challenge is to provide experience working with numerical data in a file and generating summary information. Requirements: Create a program called numstat.py that reads a series of integer numbers from a file and determines...

  • Write a program that reads a file named input.txt and writes a file that contains the...

    Write a program that reads a file named input.txt and writes a file that contains the same contents, but is named output.txt. The input file will contain more than one line when I test this. Do not use a path name when opening these files. This means the files should be located in the top level folder of the project. Do not use a copy method that is supplied by Java. Your program must read the file line by line...

  • Write a program that reads an integer k from user and finds the number of elements...

    Write a program that reads an integer k from user and finds the number of elements that are divisible by k in the file assignment4.txt. A number n is divisible by k if n = kx for some integer x > 0. You can use the mod operator % to test for divisibility. The file assign4.txt has integer values in the range [0,100 ]. You should use end-of-file controlled loop for this problem. Sample execution is given below. Assume the...

  • Write a C Program that: - Creates an input file (input.txt) - Take user inputted integer...

    Write a C Program that: - Creates an input file (input.txt) - Take user inputted integer for number of lines in the input file - accepts inputted text from command line to the input file (input.txt) - saves and closes file. (input.txt) - reopens and displays the newly inputted contents of the file

  • In C++, write a program that reads a postfix expression from an input file. Then, the...

    In C++, write a program that reads a postfix expression from an input file. Then, the program should evaluate the postfix format and display the results. Use these concepts for the program: 1) Struct Node 2) Enqueue and Dequeue 3) Push and Pop 4) DO NOT USE classes 5) Possibly Stack Precondition: The expression will be read from a file (input.txt) that contains a single line. There will be no spaces between the operands and the operators. The following operators...

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