Here is what i got. I need to count the Uppercase entered in a string. Can someone help me?

Enter string: The Brown Fox
#of Upper Case: 3


My Progress:

#include<iostream>
#include<string>
usingnamespace std;
int main()
{
char string[15];
cout<<"Enter string: ";
cin.getline(string,15);
.
.
.
.
}
I need the next solution thanks!

Edited 4 Years Ago by jman2011: n/a

Here is a hint: it involves #include <cctype> (or #include <locale> ) and std::isupper .

Here is a hint: it involves #include <cctype> (or #include <locale> ) and std::isupper .

No condition

if(isupper(c)) something

try this it works

#include<iostream.h>
#include<conio.h>
#include<string.h>
class string
{
char *str;
public:
      void input()
      {
       cout<<"\nenter the string"<<endl;
       cin>>str;
       }
      void display()
      {
       cout<<"\n"<<str;
      }
      int friend upper(string);
};
int upper(string a)
{
int j=0;

while((*a.str)!='\0')
  {
   if((*a.str)>=65&&(*a.str)<91)
   {
   j++;
   (a.str)++;
   }
   else
   (a.str)++;
   }
  return(j);
 }



int main()
{
clrscr();
int n;
 string b;
 b.input();
 b.display();
n=upper(b);
cout<<"no of upper case letters are::"<<n;
getch();
return(0);
}

:)

Comments
I hope he passes the class on your work. Maybe you can do his next assignment too...

Yeah... but just using the code i gave above is a substitute for all of it..
Isupper resides in the standard library with the same procedure u mentioned here.. Why write the whole code, when there already exists a direct function for it ??

Since we appear to be giving away code these days, you can do this in a single line using std::count_if :

#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>

int main()
{
    /* Read the target sentence into a std::string */
    std::string sentence;
    std::cout << "Enter a sentence:" << std::endl;
    getline( std::cin, sentence );

    /* Here's the actual call that counts the number of upper case letters */
    size_t iUpperCount = std::count_if( sentence.begin(), sentence.end(), isupper );

    /* Output the result */
    std::cout << "There are " << iUpperCount << " uppercase letters" << std::endl;

    return 0;
}

You're potentially not expected to know about the standard algorithms in whatever course this task is for, but it's always good to know that they're there :)

Edited 4 Years Ago by ravenous: n/a

Yeah... but just using the code i gave above is a substitute for all of it..
Isupper resides in the standard library with the same procedure u mentioned here.. Why write the whole code, when there already exists a direct function for it ??

Yeah... and by just using the built in functions, what do you learn? How to use a built in function. What if your next language doesn't have that built in function? You can't program the task...

And

Since we appear to be giving away code these days

thread closed...

This question has already been answered. Start a new discussion instead.