1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
In-s [12.5K]
3 years ago
10

Write a new program indent.cpp that enhances the program from the previous task. As it reads the input line by line, it should a

lso count the number of open and closed { } in it, and keep track of how many blocks is currently open at the beginning of each line.
Computers and Technology
1 answer:
Alborosie3 years ago
6 0

Answer:

see explaination

Explanation:

#include <iostream>

#include <conio.h>

#include <string>

using namespace std;

//Define the function to count a

// specific character in a line.

int countChar(string line, char c)

{

//Define the variable.

int tc = 0;

//Iterate through the string.

for (int i = 0; i < line.length(); i++)

{

//Find the matching character.

if (line[i] == c)

tc++;

}

//Return the character counts.

return tc;

}

//Define the function to remove the spaces.

string removeSpace(string input)

{

//Find the string length.

int strlength = input.length();

//Itearte through the string.

for (int i = 0; i < strlength; i++) {

//set the value.

i = 0;

//Check for the spaces.

if (input[i] == ' ') {

//Remove the extra space.

for (int j = 0; j < strlength; j++) {

input[j] = input[j + 1];

}

//Update the string length.

strlength--;

}

//if there is no extra space left.

else

break;

}

//Return the input string

return input;

}

//Define the main function.

int main() {

//Define the variables.

int n, ind = 0, ob = 0;

string lines[100], input;

int max = 0;

//Prompt the user for input.

cout << "Enter lines one by one: " << endl;

//Get the user input and exit when

// user enters twice after the input.

do

{

getline(cin, input);

//Remove the extra space.

input = removeSpace(input);

//Store the line by line input in the

//String array.

if (input.length() > max)

max = input.length();

lines[ind++].append(input);

} while (!input.empty() != 0);

//Set the value for number of lines.

n = ind;

cout << endl;

//Dsipaly the message

cout << endl << "Indented code is:" << endl << endl;

//Iterate through the string array.

for (int i = 0; i <= n; i++)

{

string tab = "";

//Check for the closing braces.

int close = countChar(lines[i], '}');

//Set the value for braces.

ob -= close;

//Indent the code.

for (int j = 0; j < ob; j++)

{

tab += " ";//it takes 4 whitespace

//tab+= "\t";//it takes 8 whitespace

}

//Print the line.

cout << tab << lines[i]<< endl;

//Check for the opening braces.

int op = countChar(lines[i], '{');

//Update the opening brace count.

ob = ob + op;

}

//system("pause");

//Return the value 0.

return 0;

}

You might be interested in
Before becoming romantically involved with a coworker you should
astra-53 [7]
You should make sure no one is looking and make sure you have protection
7 0
3 years ago
Read 2 more answers
Your boss is trying to modify a PDF file that he made a year ago. He asks you what he can use to do this. Which of the selection
Masteriza [31]
The answer is b. Office 2013
3 0
3 years ago
Read 2 more answers
Gigano Mobiles, a smartphone manufacturer, is going to release its new flagship device next month. The Chief Executive Officer (
ser-zykov [4K]

Answer:

trhrt

Explanation:

rhshnbbfsfhnsdfbhddbh

7 0
3 years ago
A class car and its subclass bmw each have a method run(), which was written by the developer as part of the class definition. i
krok68 [10]

The answer is : the run() method defined in BMW will be called.

run() BMW

5 0
3 years ago
Regarding the excerpt, what synthesized information helps spread a message to a large audience? Check all that apply. taking adv
frutty [35]

The question is incomplete! Complete question along with answer and step by step explanation is provided below.

Question:

Read the excerpt from News Articles about Bullying.

Aside from his website, Jaylen has appeared on numerous TV networks, chatted via Skype with college education students nationwide and spoken at the Florida Teachers Conference in Orlando in front of more than a thousand educators.

Regarding the excerpt, what synthesized information helps spread a message to a large audience? Check all that apply

1. taking advantage of technology

2. being good at public speaking

3. appearing on a television program

4. speaking mostly to college students

5. presenting at professional conferences

Answer:

The correct options are 1, 2, 3 and 5

Explanation:

In order to convey the message to a large audience, an individual can adopt certain measures that can ensure efficient spread of message.

Jaylen used technology (Skype) to chat with students nationwide, therefore, option 1 is correct.

Speaking in front of more than a thousand educators at the Florida Teacher Conference clearly suggests that Jaylen is good at public speaking, therefore, option 2 is correct.

Jaylen appeared on numerous TV networks as well as she presented at professional conferences which helps in spreading the message across a large audience, therefore, option 3 and 5 are also correct.

It is not necessary to speak to only college students, she can speak to students of all education levels to spread her message to large audience, therefore, option 4 is not correct.

7 0
3 years ago
Other questions:
  • Temporary storage location for cutting and pasting
    9·1 answer
  • Which command let’s you increase or decrease the on-screen magnification of your document
    11·1 answer
  • What is the acronym that helps you remember the order of math operations?
    9·2 answers
  • Which of the following people choose a career path for the right reasons
    12·2 answers
  • All of the following are current key technology trends raising ethical issues except:_________
    13·1 answer
  • Describe and compare imperative (C), functional (SML) and logic (Prolog) programming paradigms.
    9·1 answer
  • Which of the following is true of Chinese Opera: Two opera centers emerged Beijing and Yangzhou 300-400 forms of opera arose in
    10·1 answer
  • What aspect should you consider before adding pictures to a document?
    8·2 answers
  • Write a program that repeatedly reads in integers until a negative integer is read. The program keeps track of the largest integ
    9·1 answer
  • Do you want my hero academia?<br><br><br><br><br><br> if so, who's your favorite character :&gt;
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!