Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a complete C++ program which ignores any lower case (A to Z and a to z) en

ID: 3546803 • Letter: W

Question

                    Write a complete C++ program which ignores any lower case (A to Z and a to z) entered by the user from the keyboard and counts the number of characters that are not letters.                     Your program should output to the file letters.out the upper case letters entered by the user and their count. Your program should stop after three                     letters are read. Your program should work for any character entered not just the one entered in the example below. Assume the user enters only letters, and                     that each letter is seperated by a space.                 

                    
                

                    Example:                 

                    If the user enters a # 3 $ ! B / * F

                    
                

                    The file letters1.out will contain # 3 $ ! / * 6

                    
                

                    where 6 represents the number of upper case letters entered by the user.                 

Explanation / Answer

#include<iostream>

#include<fstream>

using namespace std;


int main(){

ofstream myFile;

myFile.open("a.out");

string x;

getline(cin, x);

int i, count = 0, l = 0;

for(i = 0; i < x.size(); i++){

if((x[i] >= 97 && x[i] <= 122) || (x[i] >= 65 && x[i] <= 90)){

l++;

if(l == 3) break;

continue;

}

else{

if(x[i] != ' '){

myFile << x[i] << " ";

count++;

}

}

}

myFile << count;

myFile.close();

cout << "The result has been saved in file a.out in the same directory of the program ";

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote