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
Without a well-designed, accurate database, executives, managers, and others do not have access to the ____________________ they
ohaa [14]

Answer:

Information

Explanation:

Good decisions are normally based on facts which are tangible information that can be analysed to show trends of key figures such as sales, income, production that are so critical in business. A well-designed and accurate database captures and stores these figures in an organised way which will enable the information or data to be analysed to make informed decisions.

6 0
2 years ago
________ is the application of statistical techniques to find patterns and relationships among data for classification and predi
Finger [1]

Answer:          

Data Mining

Explanation:

  • Data Mining is also called knowledge discovery.
  • It is a computer aided technique of searching and evaluating a bulk of data in order to obtain useful information.
  • This technique searches through the data to find hidden patterns and uses statistical methods to find relationship among data for finding predictive information and for classification of data.
  • This is a mixture of different disciplines which include machine learning, statistics and artificial intelligence and also some mathematical methods.
  • Often the useful information is extracted from enormous database using modeling technique which is used to build a model from instances of the data where the solution is known and later apply this model on the instances where the solution is unknown.
  • In unsupervised data mining, the data analysis is not done by using modeling technique. In other words the labels are provided in order not draw inferences and prediction from data sets. Example is clustering.
  • In supervised data mining the model is developed to make inferences and classification. Example is neural networks.
  • For example data mining is used in Medicine industry to provide more accurate diagnostics and treatments on the basis of patient's medical history , physical examination or different patient tests data.
  • Data mining also makes it possible to manage health resources more efficiently and cost-effectively by detecting risks, predicting diseases in certain sections of the population or predicting hospitalization duration.
4 0
3 years ago
You work in an office that uses Linux and Windows servers. The network uses the IP protocol. You are sitting at a Windows workst
Aleksandr-060686 [28]

Answer:

PING

Explanation:

To check if there's still connectivity between the computer and server, I would use the ping command.

The ping command is primarily a TCP/IP command. What this command does is to troubleshoot shoot. It troubleshoots connection and reachability. This command also does the work of testing the name of the computer and also its IP address.

4 0
2 years ago
Use the drop-down menus to complete the steps to share a presentation through OneDrive.
charle [14.2K]

Answer:

Share

OneDrive

In real time

Send

Explanation:

5 0
3 years ago
A(n) ______ is a type of collaborative website that allows users to create, add, modify, or delete website content.
andrey2020 [161]
<span>A wiki is this type of site. The users can, anonymously or with a profile, add to or delete content already posted. This gives the community the ability to add to the overall knowledge base on a specific subject. The site tracks changes through IP addresses to make sure that changes are not done maliciously.</span>
8 0
3 years ago
Other questions:
  • A boolean variable named rsvp an int variable named selection, where 1 represents "beef", 2 represents "chicken", 3 represents "
    14·1 answer
  • Write multiple if statements. if caryear is 1969 or earlier, print "probably has few safety features." if 1970 or higher, print
    6·1 answer
  • When you perform an in-place upgrade to windows 8.1 from windows 7, what will be names of the “windows” folders in windows 7 and
    5·1 answer
  • A good CRM should Integrate marketing, sales, and customer support activities measuring and evaluating the process of knowledge
    13·1 answer
  • Cine stie repede va rog mult si repede
    9·1 answer
  • X = 10<br> y = 20<br> x &gt; y<br> print("if statement")<br> print("else statement")
    6·1 answer
  • If a movie, song, or book is offered for free, is it malware?
    15·1 answer
  • Write a program that generates 100 random numbers and keeps a count of how many of those random numbers are even and how many of
    15·1 answer
  • You are a teaching assistant for an introductory computer concepts course at your local community college. The instructor asks y
    11·1 answer
  • Given a list of syntax errors from a compiler, a programmer should focus attention on which error(s), before recompiling?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!