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...
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...
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...
This Is a Chemical Engineering question but that isnt among the subjects Problem 4.39 Felder and...
This Is a Chemical Engineering question but that isnt among the subjects Problem 4.39 Felder and Rouseeau Elementary Principles Of Chemical Processes 4th Edition The hormone estrogen is produced in the ovaries of females and elsewhere in the body in men and post-menopausal women, and it is also administered in estrogen replacement therapy, a common treatment for women who have undergone a hysterectomy. Unfortunately, it also binds to estrogen receptors in breast tissue and can activate cells to become cancerous....
Chemical Engineering question. Air at 38.0°C and 99.0% relative humidity is to be cooled to 18.0°C...
Chemical Engineering question. Air at 38.0°C and 99.0% relative humidity is to be cooled to 18.0°C and fed into a plant area at a rate of 710.0 m3/min. You may assume that the air pressure is 1 atm in all stages of the process. A.) Calculate the rate at which water condenses in kg/min . B.) Calculate the cooling requirement in tons (1 ton of cooling = 12,000 Btu/h), assuming that the enthalpy of water vapor is that of saturated...
This is a question for my problem-solving class. I am really stuck and I can't see...
This is a question for my problem-solving class. I am really stuck and I can't see much of a pattern so I would appreciate if someone could draw out for each thief and explain the pattern to get the answer for 40 thieves! Question: Forty thieves, all different ages, steal a huge pile of identical gold coins and must decide how to divide them up. They settle on the following procedure. The youngest divides the coins among the thieves however...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT