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
In the borders and shading dialog box where would you look to see if your border will have two sides
arlik [135]
On the preview box? I think. 
6 0
3 years ago
Read 2 more answers
Which new development in malware caused sandbox technology to automate and introduce artificial intelligence learning
Karo-lina-s [1.5K]

AI-driven attacks caused sandbox technology to automate and introduce artificial intelligence learning. AI and machine learning can be used to fight against malware attacks.

<h3>Artificial intelligence, machine learning, and malware</h3>

Artificial intelligence (AI) refers to the ability of a PC to perform tasks done by humans due to the requirement of discernment.

Machine learning is a subdivision of (AI) based on the use of data and algorithms to mimic human learning.

Malware is malicious software generated by cybercriminals, which are capable of stealing unauthorized information.

Learn more about malware here:

brainly.com/question/399317

4 0
2 years ago
________is one color shade gradually progressing to another shade of the same color or one color progressing to another color.
posledela

Answer:

Gradient fill

Explanation:

A gradient fill is a visual effect that makes a three dimensional color look by mixing one color shade gradually progressing to another shade of the same color or one color progressing to another color. for example a dark red progressively changing to light red or red progressively changing to blue.

8 0
3 years ago
Which option ensures that different parts of the document can have different page layouts? ​
Mice21 [21]

Answer:

77777777777777777

Explanation:

8 0
3 years ago
Read 2 more answers
Under the ____________________, federal agencies must 1) review their IT systems for privacy risks, 2) post privacy policies on
nadya68 [22]

Answer:

E-Government Act of 2002.

Explanation:

The E-Government Act of 2002 is a statute of the United States of America which was enacted by the 107th U.S Congress on the 17th of December, 2002. The E-Government Act of 2002 was signed into law to facilitate the management and promotion of the US government processes and services, as well as enhance transparency and accountability between the government and the public through the application of internet-based information technology.

Under the E-Government Act of 2002, federal agencies must;

1. Review their IT systems for privacy risks.

2. Post privacy policies on their websites.

3. Post machine-readable privacy policies on their websites.

4. Report privacy activities.

3 0
3 years ago
Other questions:
  • Prominent is another word for stands out. True False
    13·1 answer
  • A ____ operating system should be capable of supporting the applications and tools necessary to support Internet operations.
    10·1 answer
  • Host A is sending Host B a large le over a TCP connection. Assume Host B has no data to send Host A. Host B will not send acknow
    14·1 answer
  • Assume that the following method header is for a method in class A.
    15·1 answer
  • How to change color of object in photoshop?
    10·2 answers
  • When a computer or digital device is used as a storage device or in the facilitation of an offense, it is argued to be ____ to t
    14·1 answer
  • How does a project charter support the project manager in getting things for the project from other people?
    6·1 answer
  • Which is an advantage of using a flat file instead of a relational database?
    9·1 answer
  • Type of cable installed on a patch panel?
    15·1 answer
  • Prior to the 1996 NEC, ____ receptacles and cords were permitted. However, now it is mandatory that a separate equipment groundi
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!