473,378 Members | 1,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

A program that prompts the user for keywords belonging to C++.

This is a revised version of a post entitled "Class to support keywords".
Please reply to this post instead of the old one.

The following program repeatedly prompts the user for C++ keywords until
'explicit' is entered. If the user fails to enter a valid keyword, the
program terminates.

#include <iostream>
#include "KeyWord.h"

int main()
{
KeyWord word;
while (std::cin >> word && word != "explicit");
return 0;
}

The following two lines of input will terminate the program:

do for while explicit
if else elseif virtual instanceof

The input given by the string "public private switch" will not.

What would a class that supports the functionality of KeyWord in the above
program look like? What are the details of the implementation of such a
class? How many changes to the implementation would be required if another
set of keywords was to be used instead?

I would appreciate help in the form of code as well as discussion. Thanks.

Jul 23 '05 #1
3 1754
Do your homework yourself.

Jul 23 '05 #2

"Jason Heyes" <ja********@optusnet.com.au> schrieb im Newsbeitrag
news:42**********************@news.optusnet.com.au ...
This is a revised version of a post entitled "Class to support keywords".
Please reply to this post instead of the old one.

The following program repeatedly prompts the user for C++ keywords until
'explicit' is entered. If the user fails to enter a valid keyword, the
program terminates.

#include <iostream>
#include "KeyWord.h"

int main()
{
KeyWord word;
while (std::cin >> word && word != "explicit");
return 0;
}

The following two lines of input will terminate the program:

do for while explicit
if else elseif virtual instanceof

The input given by the string "public private switch" will not.

What would a class that supports the functionality of KeyWord in the above
program look like? What are the details of the implementation of such a
class? How many changes to the implementation would be required if another
set of keywords was to be used instead?

I would appreciate help in the form of code as well as discussion. Thanks.

You do not really need a class for that. The whole thing you need is a
container containing strings. The container has to be filled at startup.
Afterwards you can use a find function which tells you if the keyword is in
the container. If not, it is an invalid keyword...
I don't know if there is a class for this thing. But write your own one. I'm
sure there are many listings on the web the all reserved c++ keywords.

Greets Chris
Jul 23 '05 #3
Jason Heyes wrote:
This is a revised version of a post entitled "Class to support keywords".
Please reply to this post instead of the old one.

The following program repeatedly prompts the user for C++ keywords until
'explicit' is entered. If the user fails to enter a valid keyword, the
program terminates.

#include <iostream>
#include "KeyWord.h"

int main()
{
KeyWord word;
while (std::cin >> word && word != "explicit");
return 0;
}

The following two lines of input will terminate the program:

do for while explicit
if else elseif virtual instanceof

The input given by the string "public private switch" will not.

What would a class that supports the functionality of KeyWord in the above
program look like? Probably, something with a hardcoded table of strings. Could be
a hash table, a map or something else {from the Dragon Book}.
What are the details of the implementation of such a
class? Depends on the design.
How many changes to the implementation would be required if another
set of keywords was to be used instead? Only to the table.

I would appreciate help in the form of code as well as discussion. Thanks.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chad | last post by:
I need my java program to exec an external .exe file, but the problem is that this program being exec()'ed prompts the user for two pieces of information. I am trying to get my java program to...
31
by: Brian Sabbey | last post by:
Here is a pre-PEP for what I call "suite-based keyword arguments". The mechanism described here is intended to act as a complement to thunks. Please let me know what you think. Suite-Based...
7
by: jmac | last post by:
Greetings fellow programmers, I have created a C program that has a few bugs and would like to get some help with working them out. Here is a list of the problems that I am experiencing: -...
6
by: tigrfire | last post by:
I've been working on a program to try and play a game of Craps, based on a version I found elsewhere - I didn't code the original, but I added a few things such as a balance and wager system. I'm...
0
by: joestevens232 | last post by:
I am seriously stuck and have been working on this for hours and hours and can't figure out my next step....heres the program assignment. This vending machine dispenses 1. M&Ms ($.65), 2. Chips...
3
by: haelly | last post by:
Write a program that prompts the user to enter three different integer values.If the values are not different, the program prints a message"equal values" and terminates(hint: use the return...
3
by: kaka_hunter | last post by:
#include <iostream> #include <fstream> using namespace std; const int max_tries=7; int earnings=0; int wordnum; void getword () { ifstream fin;
1
by: Kayvine | last post by:
Hi guys, this is a question I have for an assignment, it is pretty long, but I am not asking for the code(well if someone wants to write I'll be really happy, lol), but I just want to know how to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.