Question
C++

Lab Quiz #3-B Upper Case Letters Write a main() program that reads a string and calls the function int countUpper(string) which counts and returns the number of upper case letters in the string. The main) prints the result Sample inputs/outputs: nter a string: This is a C++ quIz numBer 4 This is a C++ quIz numBer 4 has 5 upper letters
0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:

#include <iostream>
#include<string> // for string class
using namespace std;
int countUpper(string s){
   int i=0;
   int c = 0;
   for(i=0;i<s.length();i++){
       if((int)s[i] >= 65 && (int)s[i] <= 90){       // checking the condition depending on ascii values
           c++;
       }
   }
   return c;      
}
int main()
{
    string s;
    cout << "Enter the string : " ;
    getline(cin, s);       // taking input using getline of string class function
   int count = countUpper(s);   // calling coutnUpper function
   cout << "\"" << s << "\" has " << count << " upper letters" << endl;       // printing the correct format
    return 0;
}


SCREENSHOT:

kasireddy@kasireddy-TravelMate-4740:~/Desktop/cg File Edit View Search Terminal Help kasireddy@kasireddy-TravelMate-4740:-/Desktop/cg$ g++ count.cpp kasireddy@kasireddy-TraveLMate-4740:/Desktop/cgs ./a.out Enter the string This is a C++ quIz numBer 4 This is a C++ quIz numBer 4 has 5 upper letters kasireddy@kasireddy-TravelMate-4740:-/Desktop/cgs /a.out Enter the string Feel free to ask any doubt. Thankyou Feel free to ask any doubt. Thankyou. has 2 upper letters kasireddy@kasireddy-TravelMate-4740:-/Desktop/cgs 1 1:45 PM KasiReddy

Add a comment
Know the answer?
Add Answer to:
C++ Lab Quiz #3-B Upper Case Letters Write a main() program that reads a string and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ 10.4 String to number Write a program that 1.reads in 4 upper case characters Converts...

    C++ 10.4 String to number Write a program that 1.reads in 4 upper case characters Converts each into its Ascii equivalent integer 3.Adds all these numbers together Converts this resulting integer to a string Prints the string. Divides the integer result by 4 Converts this back to an Ascii char prints the char

  • Exercise #4: Some Operations on Strings Write a program that uses a C-string to store a...

    Exercise #4: Some Operations on Strings Write a program that uses a C-string to store a string entered from the keyboard (in lower case letters). The program will then provide 6 options about operations performed on the input string in the form of a menu, as shown in the following sample Input/Output. The 6 operations are given below: 1. print the string 2 reverse the string 3. print the length of the string 4. convert the lower letters to upper...

  • Write a C++ program that repeatedly reads lines until an EOF is encountered. As each line...

    Write a C++ program that repeatedly reads lines until an EOF is encountered. As each line is read, the program strips out all characters that are not upper or lower case letters or spaces, and then outputs the line. Thus, the program acts as a filter and issues no prompt. There are many ways this program could be written, but to receive full credit, you must observe the following: Place your code in a file called filterChars.cpp. The program should...

  • Write a program that reads a string from the keyboard and computes the two arrays of...

    Write a program that reads a string from the keyboard and computes the two arrays of integers upperCase, and lowerCase, each of size 26. The first one represents the frequency of upper case letters and the second one represents the frequency of lower case letters in the input string. After computing these arrays, the program prints the frequencies in the following format: The frequency of the letter A= The frequency of the letter B= Assume the input string contains only...

  • Using C++ Question#1: isPalíndrome Write the following function: bool isPalindrome(int) takes an integer and returns true...

    Using C++ Question#1: isPalíndrome Write the following function: bool isPalindrome(int) takes an integer and returns true if that integer is palindrome, otherwise it returns false. The function also prints the digits of the integer in reverse order in which they were found. Write a main) function that reads an integer, calls the function is whether the integer is a palindrome or not. Palindrome), and prints Sample input/output: nter an integer: 23434 nter an integer 23432 3434 is not a palindrome...

  • Write a program in C that reads a string of bits( so either a one or...

    Write a program in C that reads a string of bits( so either a one or zero) in from the user one char at a time using the function getChar, which returns a char. hint in order to convert a char to an int, subtract the character. Then store the bits into an array. start with this: #include "stdio.h" #define MAX_BITS 32 int main() { printf("Enter up to 32 bits (hit 'enter' to terminate early): "); char bit = getchar();...

  • In Java* ​​​​​​​ Write a program that reads an arbitrary number of 20 integers that are...

    In Java* ​​​​​​​ Write a program that reads an arbitrary number of 20 integers that are in the range 0 to 100 inclusive. The program will ask a user to re-enter an integer if the user inputs a number outside of that range. The inputted integers must then be stored in a single dimensional array of size 20. Please create 3 methods: 1. Write a method public static int countEven(int[] inputArray) The method counts how many even numbers are in...

  • 1. Write a Python function that accepts a string and calculate the number of upper case...

    1. Write a Python function that accepts a string and calculate the number of upper case letters and lower case letters. Sample String : 'The quick Brow Fox' Expected Output : No. of Upper case characters : 3 No. of Lower case Characters : 12

  • 1. Write a python program that reads a file and prints the letters in increasing order...

    1. Write a python program that reads a file and prints the letters in increasing order of frequency. Your program should convert entire input to lower case and only counts letters a-z. Special characters or spaces should not be counted. Each letter and it's occurrences should be listed on a separate line. 2. Test and verify your program and it's output. ---Please provide a code and a screenshot of the code and output. Thank you. ----

  • Write a C++ program that takes a string containing a full name in lower case letters...

    Write a C++ program that takes a string containing a full name in lower case letters and outputs each part of the name separately with initial letters capitalized. The name should be in the form of first, middle, and last name, separated from each other by a single space. For example, if the name string contains "heidi kim lee" then the program would output First name: Heidi Middle name: Kim Last name: Lee

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT