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