Hi I'm Hans Welcome to my Website...
Custom Search

Facebook

PUNP-nians

PUNP-nians

Latest topics

» PM.,Grade lang po
Fri Feb 18, 2011 3:21 pm by Evildarkwarrior_18

» GRADES for SEMI Finals
Sun Oct 24, 2010 8:26 pm by amvou13

» BSIT 1 Computer Programming 1
Sun Oct 24, 2010 8:11 pm by amvou13

» AIT 1 B Computer Programming 1
Sun Oct 24, 2010 8:09 pm by amvou13

» AIT 1 A Computer Programming 1
Sun Oct 24, 2010 8:05 pm by amvou13

» BSCS 2 Design Analysis of Algorithm
Sun Oct 24, 2010 8:00 pm by amvou13

» ACT 1 Computer Hardware and Software Installation
Sun Oct 24, 2010 7:58 pm by amvou13

» ACT 2 PC Troubleshooting
Sun Oct 24, 2010 7:51 pm by amvou13

» BSCS 3 and BSIT 3 Web Development/Programming 1
Sun Oct 24, 2010 7:49 pm by amvou13

ahm

Thu Aug 26, 2010 12:47 am by elyn

bakit ang mahal ng bbyaran
sa seminar...

dpat ndi na
nmen babayaran ung fair ng bus ehhh...
sagot na dpat ng skul kc studentd kme...

dhil jan madame
tuloy nde ppnta kht pa
required....
sna aman bawasan ung bayad... Surprised

bom bom bom

Donations

RSS feeds


Yahoo! 
MSN 
AOL 
Netvibes 
Bloglines 

Shopmotion



    C++ program that will count the number of characters, integers, spaces and punctuations

    Share
    avatar
    amvou13
    Admin

    Posts : 84
    Join date : 2010-07-28
    Age : 30

    C++ program that will count the number of characters, integers, spaces and punctuations

    Post  amvou13 on Sun Oct 24, 2010 6:08 pm

    Hi everyone,

    just want to share simple program that will count the number of characters, integers, space and punctuations in a string..


    #include <iostream>
    #include <string>
    #include <cctype>
    using namespace std;

    void showValues(string, int);

    int main()
    {
    string sentence;

    cout << "Enter sentence now:n";
    getline(cin, sentence);

    showValues(sentence, sentence.length());
    return 0;
    }

    void showValues (string chars, int size)
    {
    cout << "nThe string is:"<< endl;
    for (int index = 0; index < size; index++)
    cout << chars[index];
    cout << endl;

    // Show how many????

    char ch;
    int vowelCount = 0;
    int lowerCount=0;
    int upperCount=0;
    int spaceCount = 0;
    int intCount = 0;
    int punCount = 0;
    int pos;
    int x=0;

    for (pos = 0; pos < size; pos++)
    {

    if (chars[pos])
    x++;
    }
    //space
    for (pos = 0; pos < size; pos++)
    {
    ch=(chars[pos]);

    switch(ch)
    {
    case ' ': spaceCount++;
    }
    }

    //for digits
    for (pos = 0; pos < size; pos++)
    {
    if(isdigit(chars[pos]))

    intCount++;

    }
    //for small caps
    for (pos = 0; pos < size; pos++)
    {
    if(islower(chars[pos]))

    lowerCount++;

    }

    //for big caps
    for (pos = 0; pos < size; pos++)
    {
    if(isupper(chars[pos]))

    upperCount++;

    }
    //for punctuation
    for (pos = 0; pos < size; pos++)
    {
    if(ispunct(chars[pos]))


    punCount++;

    }

    cout << "The number of letter/s and digit/s including the space in the string is: " << x << endl;
    cout << "nThere are " << spaceCount << " space/s in the string.n";
    cout << "nThere are " << intCount << " digit/s in the string.n";
    cout << "nThere are " << lowerCount << " small letter/s in the string.n";
    cout << "nThere are " << upperCount << " big letter/s in the string.n";
    cout << "nThere are " << punCount << " punctuation/s in the string.n";

    }

      Current date/time is Sun Oct 22, 2017 8:14 pm