Task A. Removing indentation Before we make a program that indents source code files, let's make...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Task A. Removing indentation Before we make a program that indents source code files, let's make a program that unindents them. Start by writing a function string removeLeadingSpaces (string line); that takes one line of code as input and returns its copy without leading spaces and tabs: int x = 1; ") == "int x = 1; 11 removeLeadingSpaces (" Make use of the function isspace defined in <cctype> to check if a character is a whitespace. Your function should probably iterate over the input string, skip all spaces, and after it finds the first non-space character, start accumulating the characters into a new string, which will be returned. Write a program unindent.cpp that reads input from cin and prints out each input line with leading spaces removed. Example: To test, create a badly indented file, for instance, called bad-code.cpp: int main() { // Hi, I'm a program! int x = 1; for (int i = 0; i<10; i++) { cout << i; cout << endl; } } int main() { // Hi, I'm a program! int x = 1; for (int i = 0; i < 10; i++) { cout << i; cout << endl; } } It will output a well-formatted program: int main() { } // Hi, I'm a program! int x = 1; for (int i = 0; i <10; i++) { cout << i; cout << endl; } int main() { // Hi, I'm a program! int x = 1; for (int i = 0; i < 10; i++) { cout << i; cout << endl; } } It will output a well-formatted program: int main() { } // Hi, I'm a program! int x = 1; for (int i = 0; i <10; i++) { cout << i; cout << endl; } Task A. Removing indentation Before we make a program that indents source code files, let's make a program that unindents them. Start by writing a function string removeLeadingSpaces (string line); that takes one line of code as input and returns its copy without leading spaces and tabs: int x = 1; ") == "int x = 1; 11 removeLeadingSpaces (" Make use of the function isspace defined in <cctype> to check if a character is a whitespace. Your function should probably iterate over the input string, skip all spaces, and after it finds the first non-space character, start accumulating the characters into a new string, which will be returned. Write a program unindent.cpp that reads input from cin and prints out each input line with leading spaces removed. Example: To test, create a badly indented file, for instance, called bad-code.cpp: int main() { // Hi, I'm a program! int x = 1; for (int i = 0; i<10; i++) { cout << i; cout << endl; } } int main() { // Hi, I'm a program! int x = 1; for (int i = 0; i < 10; i++) { cout << i; cout << endl; } } It will output a well-formatted program: int main() { } // Hi, I'm a program! int x = 1; for (int i = 0; i <10; i++) { cout << i; cout << endl; } int main() { // Hi, I'm a program! int x = 1; for (int i = 0; i < 10; i++) { cout << i; cout << endl; } } It will output a well-formatted program: int main() { } // Hi, I'm a program! int x = 1; for (int i = 0; i <10; i++) { cout << i; cout << endl; }
Expert Answer:
Answer rating: 100% (QA)
include include using namespace std string removeLeadin... View the full answer
Related Book For
Accounting Information Systems
ISBN: 9780132871938
11th Edition
Authors: George H. Bodnar, William S. Hopwood
Posted Date:
Students also viewed these accounting questions
-
Sussex Plc is planning a new product which will be sold to trade customers on 60 day credit terms. All investment and manufacturing costs will need to be paid either in the month of purchase or the...
-
Write a function called hms_to_secs() that takes three int values for hours, minutes, and secondsas arguments, and returns the equivalent time in seconds (type long). Function prototypes is given...
-
Write a MATLAB program in a script file that finds a positive integer n such that the sum of all the integers 1 + 2 + 3 + ... + n is a number between 100 and 1000 whose three digits are identical. As...
-
1. If the nominal policy interest rate is 5% and the expected rate of inflation is 3%, what is the value for the vertical intercept of the LM curve? 2. If the expected rate of inflation were to...
-
Computer technology in accounting systems and electronic transfer of funds has changed since the 1980s. Have these changes reduced or increased the likelihood of billing scheme frauds?
-
Revisiting Linear Independence: Use the Wronskian to show that the set {et, 5e-t, e3t} is linearly independent?
-
Evans \& Sons, Inc., sold \(\$ 100,000\) face value, six percent coupon rate, four-year bonds, for an aggregate issue price of \(\$ 95,000\). Calculate the total interest expense to be recorded by...
-
In a P system the lead time for a box of weed-killer is two weeks and the review period is one week. Demand during the protection interval averages 218 boxes, with a standard deviation of 40 boxes....
-
Why of the following reasons does NOT describe why some states are currently reconsidering the use of cash bail? a.Cash bail is based only on an appraisal of how dangerous someone is. b.Cash bail...
-
YWS is considering the purchase of equipment for $100,000 to fund a program that will provide the following cash inflows: Year 1 - $25,000, Year 2 - $40,000, and Year 3 - $50,000. Calculate the...
-
is the ability to bring to fruition, or produce, what ever is imagined or envisioned. Creativity O Productivity Possibility O Responsibility
-
Neil Orbison, a residenttaxpayer, purchased a propertyon15 July 2021as an investmentwiththe intentionof derivingrentalincome. Forthefollowingtransactions,calculateanyamountsthathewouldbe able to...
-
8. Three point-like charges are placed at the following points on the x-y system coordinates (q1 is fixed at x = -1.00 m, q 2 is fixed at y = +1.00 m, and q3 is fixed at x = +3.00 m. Find the...
-
What are the psychological factors underlying resistance to change among stakeholders, and how can change agents employ principles of cognitive-behavioral psychology to mitigate resistance and...
-
ABC Capital Management is one of the most prestigious asset management companies in the country. It has been managing the wealth of America for over 100 years. It utilizes various forms of...
-
One considers a steady flow down a wide plane, which is inclined to the horizontal by an angle of , under the action of gravitational force as shown in Figure 2. The depth of the fluids normal to the...
-
What is the theory, model, framework, method and weakness/strength of this research?...
-
Ball bearings are widely used in industrial applications. You work for an industrial food machinery manufacturer and your role is to design the driveshaft assembly on a new type of equipment that...
-
The With- It Company, an Internet service provider, uses direct, online processing in its customer payments business process. Data entry terminals in the cashiers department allow direct entry of...
-
What are the primary objectives of computer forensics?
-
Identify several functions that may be specialized areas of expertise in an information system department. Discuss.
-
Evans \& Sons, Inc., is authorized to issue one million shares of \$1 par value common stock. The company actually sells 700,000 shares at \(\$ 10\) per share. Prepare the journal entry to record the...
-
The Glendora Company has 200,000 shares of cumulative, five percent, \(\$ 100\) par value preferred stock outstanding. Last year the company failed to pay its regular dividend, but the board of...
-
Calculate the return on common stockholders' equity for Evans \& Sons for 2018 and 2019. Did the return improve from 2018 to 2019? Evans \& Sons, Inc., disclosed the following information in a recent...
Study smarter with the SolutionInn App