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

I need help to finish this program: //PURPOSE: This program reads data, characte

ID: 3618211 • Letter: I

Question

I need help to finish this program: //PURPOSE:   This program reads data, character by character, from standard input
// and counts the number of newline characters.  As it reads, it capitalizes
// lowercase letters and prints the revised stream of characters to standard output.
// 1. Change the program so that it changes the case of all letters and prints
//    this to standard output. That is, instead of only up-casing lowercase letters,
//    it also lower-cases uppercase letters. Do this by replacing the
//    ChangeToUpperCase function with a ChangeCase function that takes the value of
//    its single argument and returns the corresponding upper/lower-case letter,
//    as applicable. Replace the call to ChangeToUpperCase in
//    main() with a call to ChangeCase.
// 2. Have the program also count the number of tab characters in the input stream
//    and print this number out on a line after the count of newline characters.
//    Two lines of code anticipate this modification; go ahead and use this code.)

#include <iostream>

using namespace std;

// Function Prototype(s):
char ChangeCase(char ch);


int main()
{
    char inCh;              // input character
    char outCh;             // output character
    int  newlineTally = 0;  // Tally of ' ' characters read
    int  tabTally = 0;      // Tally of ' ' characters read

    cin.get(inCh);
    while (cin)
    {
        Modify the following code so that it can also count the number of tabcharacters as well as new line characters in the input streamif (inCh == ' ')newlineTally++;outCh = ChangeToUpperCase(inCh);cout << outCh;cin.get(inCh);
    }

    cout << endl << endl;
    cout << newlineTally << " newlines encountered." << endl;
    cout << tabTally     << " tabs encountered."     << endl;

    return 0;
}

// FUNCTION: ChangeToUpperCase --> ChangeCase
// TASK: If the value of the single argument to the function is a
//       lowercase letter, the function returns the corresponding
//       uppercase letter;  otherwise, simply returns the argument's value.

Modify the following code so that it changes the case of all letterschar ChangeToUpperCase(char ch){char newCh; // character to return// Is ch a lowercase letter?if ( ch>='a' && ch<='z' )newCh = ch + ('A'-'a');elsenewCh = ch;return newCh;} I need help to finish this program: //PURPOSE:   This program reads data, character by character, from standard input
// and counts the number of newline characters.  As it reads, it capitalizes
// lowercase letters and prints the revised stream of characters to standard output.
// 1. Change the program so that it changes the case of all letters and prints
//    this to standard output. That is, instead of only up-casing lowercase letters,
//    it also lower-cases uppercase letters. Do this by replacing the
//    ChangeToUpperCase function with a ChangeCase function that takes the value of
//    its single argument and returns the corresponding upper/lower-case letter,
//    as applicable. Replace the call to ChangeToUpperCase in
//    main() with a call to ChangeCase.
// 2. Have the program also count the number of tab characters in the input stream
//    and print this number out on a line after the count of newline characters.
//    Two lines of code anticipate this modification; go ahead and use this code.)

#include <iostream>

using namespace std;

// Function Prototype(s):
char ChangeCase(char ch);


int main()
{
    char inCh;              // input character
    char outCh;             // output character
    int  newlineTally = 0;  // Tally of ' ' characters read
    int  tabTally = 0;      // Tally of ' ' characters read

    cin.get(inCh);
    while (cin)
    {
        Modify the following code so that it can also count the number of tabcharacters as well as new line characters in the input streamif (inCh == ' ')newlineTally++;outCh = ChangeToUpperCase(inCh);cout << outCh;cin.get(inCh);
    }

    cout << endl << endl;
    cout << newlineTally << " newlines encountered." << endl;
    cout << tabTally     << " tabs encountered."     << endl;

    return 0;
}

// FUNCTION: ChangeToUpperCase --> ChangeCase
// TASK: If the value of the single argument to the function is a
//       lowercase letter, the function returns the corresponding
//       uppercase letter;  otherwise, simply returns the argument's value.

Modify the following code so that it changes the case of all letterschar ChangeToUpperCase(char ch){char newCh; // character to return// Is ch a lowercase letter?if ( ch>='a' && ch<='z' )newCh = ch + ('A'-'a');elsenewCh = ch;return newCh;}

Explanation / Answer

//PURPOSE:  This program reads data, character by character, from standardinput
// and counts the number of newline characters. As it reads,it capitalizes
// lowercase letters and prints the revised stream of characters tostandard output.
// 1. Change the program so that it changes the case of all lettersand prints
//    this to standard output. That is, instead ofonly up-casing lowercase letters,
//    it also lower-cases uppercase letters. Do thisby replacing the
//    ChangeToUpperCase function with a ChangeCasefunction that takes the value of
//    its single argument and returns thecorresponding upper/lower-case letter,
//    as applicable. Replace the call toChangeToUpperCase in
//    main() with a call to ChangeCase.
// 2. Have the program also count the number of tab characters inthe input stream
//    and print this number out on a line after thecount of newline characters.
//    Two lines of code anticipate thismodification; go ahead and use this code.)

#include<iostream>

using namespacestd;

// FunctionPrototype(s):
char ChangeToUpperCase(char ch);


int main()
{
    charinCh;             // input character
    charoutCh;            // output character
    int newlineTally = 0; // Tally of' ' characters read
    int tabTally =0;      // Tally of ' ' charactersread

   cin.get(inCh);
    while (cin)
    {
      if (inCh == ' ')
       newlineTally++;
   if(inCh==' ')
        tabTally++;
    outCh = ChangeToUpperCase(inCh);
    cout << outCh;
    cin.get(inCh);

   }

    cout<< endl << endl;
    cout << newlineTally << " newlinesencountered." << endl;
    cout << tabTally    << " tabs encountered."     <<endl;
    return 0;
}

// FUNCTION:ChangeToUpperCase --> ChangeCase
// TASK: If the value of the single argument to the function isa
//       lowercase letter, thefunction returns the corresponding
//       uppercase letter; otherwise, simply returns the argument's value.


char ChangeToUpperCase(char ch)
{
char newCh;   // character to return
// Is ch a lowercase letter?
if ( ch>='a' && ch<='z' )
newCh = ch -32;
else
newCh = ch;
return newCh;
}

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