Write a C++ program using #include<iostream> and #include <cctype>.The program s
ID: 3735988 • Letter: W
Question
Write a C++ program using #include<iostream> and #include <cctype>.The program should first take string inputs (line by line) and get rid of the empty space before each line's first non-blank character, the program will then iterate through the strings (keeping track of the { and } braces) and indent properly (like the last example given), outputting the correct indented strings. THE CORRECT OUTPUT INDENTATION OF INPUTTED STRINGS IS THIS PROGRAM'S PURPOSE! Please solve as soon as you can (due in a few hours!). Thank you.
Explanation / Answer
here is your program : ---------->>>>>>>>>
#include<iostream>
#include<cctype>
using namespace std;
int countChar(string line,char c){
int count = 0;
for(int i = 0;i<line.length();i++){
if(line[i] == c){
count++;
}
}
return count;
}
int main(){
string line;
string temp;
temp.reserve(100);
int st = 0;
string cmp = "//";
cout<<" Enter Text line By Line completion type // ";
while(true){
cin>>temp;
if(temp == cmp){
break;
}
st = 0;
for(int i = 0;i<temp.length();i++){
if(st == 1){
line.push_back(temp[i]);
}
if(st == 0 && temp[i] != ' '){
st = 1;
}
}
}
int n1 = countChar(line,'{');
int n2 = countChar(line,'}');
if(n1 > n2){
cout<<" Total Open Braces = "<<(n1-n2);
}
if(n1 == n2){
cout<<" No Open braces ";
}
if(n1 < n2){
cout<<" Closed Braces is "<<(n2-n1)<<" more than open braces";
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.