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
(b) The CPU is responsible for processing instructions.
Yakvenalex [24]

Answer:

The answer to this question is given below in the explanation section.

Explanation:

The CPU is responsible for processing instruction. CPU instruction processing goes through three stages. Fetch, Decode, and Execute.

When the program runs,  program code is copied from secondary storage into main memory. CPU's program counter set to the first instruction of the program stored in memory where the program starts executing.

When a program is being executed, it goes through fetch-decode-cycle. which repeats over and over again until reaching the STOP instruction.

The processor check which next instruction to be executed, then the processor fetches that instruction value from the memory location.  once the instruction being fetched it gets decoded and executed. This instruction processing cycle repeating until the CPU finds a stop instruction.

6 0
3 years ago
Read 2 more answers
gven an IP address and mask of 192.168.12.0/24, design an IP addressing scheme that satisfies the following requirements. Subnet
Reika [66]
Uh 69 +23= 92
Hope this helps :)
8 0
3 years ago
A document called a system requirements report describes the objectives for the information system.
kkurt [141]
A, true. Requirements describe the objectives of any assignment.
6 0
2 years ago
Nina aspires to be a digital media specialist. What should Nina be familiar with in order to pursue this career?
never [62]
D because they do more about software
6 0
3 years ago
Read 2 more answers
Write a python program that takes two lists as input from the user, multiplies the index wise elements of the two lists and adds
nevsk [136]

Answer:

list_one=[]

list_two=[]

list_three=[]

str1=input("list_one:")

for i in str1:

   if i.isdigit():

       i=int(i)

       list_one.append(i)

   elif i.isalpha():

       list_one.append(i)

str2=input("list_two:")

for i in str2:

   if i.isdigit():

       i=int(i)

       list_two.append(i)

   elif i.isalpha():

       list_two.append(i)

print(list_one)

print(list_two)

if len(list_one)==len(list_two):

   for i in range(len(list_one)):

       multiply=list_one[i]*list_two[i]

       add=str(multiply)

       list_three.append(add)

else:

   print("Index out of bound")

n=0

for i in list_three:

   if i.isdigit():

           n+=1

   else:

       print("The list has some non number values")

print(list_three)

3 0
2 years ago
Other questions:
  • When you declare a string data type, you are actually creating an object from the?
    5·1 answer
  • a one-two paragraph summary on the Running Queries and Reports tutorials. Apply critical thinking and an academic writing style
    6·1 answer
  • Select the steps for adding artwork into a placeholder on a presentation slide
    11·1 answer
  • "The ______ of an operational system that supports an organization includes policies, requirements, and conditional statements t
    12·1 answer
  • For the description below, develop an E-R diagram:
    9·1 answer
  • PLEASE ANSWER ASAP
    7·1 answer
  • Obtaining the data of a video file from a flash drive is an example of a(n) _________ operation.
    6·1 answer
  • How many strings with five or more characters can be formed from the letters in seeress?
    15·1 answer
  • Fix the regular expression used in the rearrange_name function so that it can match middle names, middle initials, as well as do
    10·1 answer
  • 3.1.14 Wormhole CodeHS <br><br> May I have it in a copy and paste, please?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!