Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,194 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,347 people online right now. Registration is fast and FREE... Join Now!




ctrl +z to exit program

 
Reply to this topicStart new topic

ctrl +z to exit program

michael1201
7 Jul, 2008 - 09:22 AM
Post #1

New D.I.C Head
*

Joined: 2 Jul, 2008
Posts: 13

i wrote a program and part of the instructions said "Write a program that prompts the user to enter text from the keyboard. The text is read until Ctrl+Z is entered, i.e., the end of file is reached." i dont completely understand wat this means then it gave an example.

The following input:
Th1s 1s a test.^Z
Should produce the following result:
1 2
a 1
e 1
h 1
s 3
t 3
Special symbols:4

if anyone can look at my program and tell me if i did it correctly i would appreciate it Thank You In Advance biggrin.gif.

CODE
#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;
#include<string>
#include<cctype>


string toUpper(string text)
{
    string ret(text);
    for(int i=0;i<text.length();i++)
    {
        ret[i]=toupper(text[i]);
    }
    return ret;
}


void printReport(int letters[], int numbers[], int special){
    for (int i = 0; i < 10; i++)
    {
        if (numbers[i] > 0)
        {
            cout << i << " - " << numbers[i] << endl;
        }
    }

    for (int i = 0; i < 26; i++)
    {
        if (letters[i] > 0)
        {
            cout << char(i + 65) << " - " << letters[i] << endl;
        }
    }

    cout << "Special Symbols = " << special << endl;
}

void count(string input){
    input = toUpper(input);
    int letters[26] = {};
    int numbers[10] = {};
    int special = 0;
    for (int i=0; i<input.length();i++)
    {
        char c = input[i];
        int ascii = (int)c;
        if ((ascii >= 65) && (ascii <= 90))
        {
            letters[ascii - 65]++;
        }else if((ascii >= 48) && (ascii <= 57))
        {
            numbers[ascii - 48]++;
        }else
        {
            special++;
        }
    }
    
    printReport(letters, numbers, special);
}



int main()
{
    string input;
    cout << "Enter in the input text: ";
    getline (cin, input);
    count(input);
    
    system("pause");
    return 0;
}


User is offlineProfile CardPM
+Quote Post

captainhampton
RE: Ctrl +z To Exit Program
7 Jul, 2008 - 10:18 AM
Post #2

Jawsome++;
Group Icon

Joined: 17 Oct, 2007
Posts: 518



Thanked: 2 times
Dream Kudos: 825
My Contributions
This should explain all of your Ctrl-Z needs
http://cis.stvincent.edu/carlsond/swdesign...ic/streams.html
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/4/08 12:08PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month