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...
-
Explain how a company might use a currency swap to hedge its foreign exchange risk on a foreign currency borrowing.
-
The following diagram shows the LRAC and MC curves for a natural monopolylong-run average costs are falling over the entire range of the demand curve. a. Show on the diagram the price and quantity...
-
What is corporate governance?
-
The plant assets section of the comparative balance sheets of Anders Company is reported below. Refer to the balance sheet data above from Anders Company. During 2015, equipment with a book value of...
-
Write tan sin - 1 in algebraic form
-
From elementary physics, we know that when an object is subjected to a constant acceleration a, the relationship between distance d and time t is given by d = at2. Suppose that, during a seek, the...
-
Smoky Mountain Corporation makes two types of hiking boots-the Xtreme and the Pathfinder. Data concerning these two product lines appear below: Selling price per unit Direct materials per unit Direct...
-
A two-phase power supply is represented by the expression; =4sin(3)3cos(3) a. Graph the two wave forms separately and calculate the instantaneous voltage supplied at 3 seconds. b. Calculate the...
-
1. Which departments at KoalaTech have the most impact on quality? What role should each department play in helping KoalaTech improve overall quality? 2. What recommendations would you make to Nancy...
-
Explain the importance of bond ratings, and list some of the criteria used to rate bonds. Differentiate between interest rate risk, reinvestment rate risk, and default risk.
-
Does Interfund transfer ( in and out ) affect the ending fund balance in the statement of revenues, expenditures, and changes in fund balance? If so does transferring out decrease and transferring in...
-
A client of the firm holds the following shares in an investment portfolio: Ocka Limited $60,000,000 beta 0.9 Techno Limited $40,000,000 beta 1.3 Mega Bank Limited $80,000,000 beta 0.8 a. Explain the...
-
AlwaysRain Irrigation, Inc., would like to determine capacity requirements for the next four years. Currently two production lines are in place for making bronze and plastic sprinklers. Three types of
-
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.
-
Bond Features Define the following terms related to bonds payable. Debenture bonds Secured bonds Convertible bonds Callable bonds Face value of the bonds Face rate of interest Issue price
-
Do you agree with this statement: All liabilities could be legally enforced in a court of law? (Appendix)
-
Effect of Bond Issuance A bond with a face value of $10,000 is issued at a discount of $800 on January 1, 2008. The face rate of interest on the bond is 7%. Required 1. Was the market rate at the...
Study smarter with the SolutionInn App