Question

In: Computer Science

Engineering problem solving with C++ by Delores Maria Etter Jeanine A. Ingber Page 247 Question 15...

Engineering problem solving with C++ by Delores Maria Etter Jeanine A. Ingber

Page 247

Question 15

Write a program that reads a file containing an integer and floating-point values separated by commas, which may or may not be followed by additional whitespace. Generate a new file that contains the integers and floating-point values separated only by spaces; remove all whitespace characters between the values, and insert a single space between the values. Do not change the number of values per line in the file.

Solutions

Expert Solution

#include <iostream>
#include <fstream>
#include <string>
#include <algorithm> 
using namespace std; 
// removing space from the string
string remSpaces(string str) 
{ 
// remove all spaces
        str.erase(remove(str.begin(), str.end(), ' '), str.end()); 
        // return string
        return str; 
} 

int main () {
        // declaring variables 
  string line,str;
        //  declaring myoutfile object
  ofstream myOutfile;
  
  myOutfile.open ("output.txt");
  ifstream myfile ("input.txt");
  if (myfile.is_open())
  {
        // read line by line from the file
    while ( getline (myfile,line) )
    {
        // calling removespaces function assaigning into string
        
        str = remSpaces(line);
        // replacing comma with spacces
        replace(str.begin(), str.end(), ',', ' ');
        // writing into file with new line character
        myOutfile <<str<<"\n" ;
    }
    // closing both files
    myfile.close();
    myOutfile.close();
  }
// if file is not found will give 
  else cout << "file not found"; 

  return 0;
}

Related Solutions

In the light of engineering design processes and problem solving methodology, expand on the following; Definition...
In the light of engineering design processes and problem solving methodology, expand on the following; Definition of the problem Gathering of information Generation of alternative solution Evaluation of alternatives Solution of the problem Communication of the results
You must use Excel for solving all the problems In problem 13.9 on page 501, an...
You must use Excel for solving all the problems In problem 13.9 on page 501, an agent for real estate company wanted to predict the monthly rent for one-bedroom apartments, based on the size of the apartment. The data are stored in rentsliverspring. Use the results of that problem. a. at the 0.05 level of significance, is there evidence of a linear relationship between the size of the apartment and the monthly rent? b. Construct at 95% confidence interval estimate...
answer the problem solving under investment management? Problem 5 Find the future value of a 15-year,...
answer the problem solving under investment management? Problem 5 Find the future value of a 15-year, $300 per year annuity at 6%. The answer is:   Problem 6 How much would you have to deposit now to have $15,000 in 8 years if interest is 7%? The answer is:   Problem 7 Find the present value of a 3-year, $500 annuity at 4%. The answer is:   Problem 8 Find the present value of a $400 payment received each six months for 3...
The toughest part of the problem-solving process is _____. Question 2 options: clarifying the problem identifying...
The toughest part of the problem-solving process is _____. Question 2 options: clarifying the problem identifying the problem that you want to work on selecting your best option generating multiple solutions Question 3 (1 point) Although a _____ allows managers to take the business concept beyond the idea stage, it doesn't accomplish the actual work. Question 3 options: plan vision mission goal Question 4 (1 point) Long-range planning that establishes an overall course of action for a company is generally...
Discuss differences in brain activity associated with solving a problem by insight and solving a problem...
Discuss differences in brain activity associated with solving a problem by insight and solving a problem through step-by-step analysis.
Unit 5 : PROBLEM SOLVING AND DECISION MAKING 1- Define: a. Problem. b. Decision making. c....
Unit 5 : PROBLEM SOLVING AND DECISION MAKING 1- Define: a. Problem. b. Decision making. c. Scientific decision making. d. Complexity in scientific decision making. e. Information. f. A management information system (MIS). g. Creativity. 2- Describe the PDCA cycle as model to solve problem.(Fig 1 294). 3- Describe the Toyota method for problem solving.(Fig 3-296). 4- Define the decision-making model.(fig 4-299) 5- What is the problem caused by information overload? 6- What is the Creative Process? and How to...
Discuss differences in brain activity associated with solving problem by insight and solving a problem through...
Discuss differences in brain activity associated with solving problem by insight and solving a problem through step-by-step analysis.
Question 6 (This is multiple choice question 15-20 on page 466, but without the answers.) As...
Question 6 (This is multiple choice question 15-20 on page 466, but without the answers.) As a result of analytical procedures, the independent auditor determines that the gross profit percentage has declined from 30% in the preceding year to 20% in the current year. Required: Explain your thought process as you decide what to do.
Part I: PROBLEM- SOLVING. Direction: Answer the requirement for each problem. Show your work. Question 1....
Part I: PROBLEM- SOLVING. Direction: Answer the requirement for each problem. Show your work. Question 1. XYZ Corporation has provided the following data from its activity-based costing system: Activity Cost Pool Total Cost Total Activity Assembly $ 942,480 66,000 Machine Hours Processing Orders $ 85,050 1,800 Orders Inspection $ 126,854 1,820 Inspection Hours Furthermore, data concerning product ABC appears below: Selling price per unit $ 150.20 Direct Materials Cost per unit $ 20.06 Direct labor Cost per unit $ 45.04...
Problem Solving/Goal Setting Checkpoint Provide an example of a time when you used the problem solving...
Problem Solving/Goal Setting Checkpoint Provide an example of a time when you used the problem solving and decision making. What is the role of creativity in the problem solving process? What are three ways that you can increase your personal creativity? Respond to the following in a essay: Describe a time you encountered a problem that required you to use the problem solving and decision making steps on page 150 of the textbook. How did you solve the problem using...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT