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.

basic

so what i am trying to do is write a program for a robotics project (think remote control using keyboard as input). To start I am writing this thing as a C++ console app.

Now I have taken a coarse on OOP so I have a decent knowledge of the syntax however my understanding of structure is very lacking (I would personnally blame the coarse for being a memorization session but blame wont get my anywere). while I could do this in C I mostly want to do this in C++ for education purposes.

Now, as far as the program goes I could and have in the past done this same thing very easily in C quite easily by simply have the program:
1) Collect user input
2) Perform the appropriate action,
3) waste some time with nested for loops or transmit signal, receive confirmation signal, stop transmitting.
4) and then check for user inputs again

with all of this in a while(1) things are somewhat easy.
however it would have inherent flaw that the program is tied up while waiting! (could this be solved via use of interrupts perhaps?)

would this be written as a lengthly driver with one class and one object, were the driver simply calls a bunch of functions:
right now it occured to me that i should make input the object and give it characteristics (like isActive, currentState, timeCollected etc)

is my interpretation that the input should be the object and there should be one class correct?

much thanks in advance
Jan 17 '09 #1
7 1661
My honest apologies regarding the title, that was a little bit of an "oops." and now I can't seem to find an edit button so I assume posts are uneditable.

Edit (oh the irony): Initial posts are uneditable >.>
Jan 18 '09 #2
I hadn't even known one could change the focus of the switch in this way. Pretty neat, maybe the state machine stuff they taught me in school is in some way useful ;)

question though:
I was going through the c implementation you added (to make sure it made sense to me before I got to OO)
I was confused by "state = 0" since there is no case 0: or default:
Also I had to remove break; since it was breaking from the entire switch and not checking the value of state.

That been said the concept is the most important thing!

Also if anyone reading this knows a good site (or perhaps fabulous book if(bookAwesomeness > siteAwesomeness) that doesn't bother itself with syntax and just goes over oop and how it should be implemented structure wise that would be invaluable!

Thanks!
Jan 18 '09 #4
so I have been going over this some more because I am very much beginning to see how advantageous this [using a state machine] can be, especially if I can have the switch move between output states and read in states quickly, updating the list of outputs making my program better handle simultaneous inputs.

That being said I am having a problem. I sort of got to it above and thought it was a simple case of to break or not to break...

for:
Expand|Select|Wrap|Line Numbers
  1. switch(state){
  2. ...
  3. default:
  4. break;
  5. }
if I use break in my 1st case, it exits the switch entirely
if I don't use break, the switch does not check the value of state when it decides what to do next it just moves down my list until it gets to default:

what am I doing wrong? I looked via google, some people are doing this way and don't seem to have my problem, some are using GOTO... which I understand is a baaaaad idea and some are even putting it in a while loop (which actually makes some sense to me, but I want to understand why this isn't working without the while for me!)

Thanks!
Jan 19 '09 #5
JosAH
11,448 Expert 8TB
Would something like the following solve your problem?

Expand|Select|Wrap|Line Numbers
  1. for (int state= STARTSTATE; state != ENDSTATE; ) {
  2.    switch (state) { // yout state machine
  3.       // don't fall through the cases but switch the state value instead
  4.    }
  5. }
  6.  
kind regards,

Jos
Jan 19 '09 #6
weaknessforcats
9,208 Expert Mod 8TB
Yes, heed JosAH. The state machine requires that each state know the successor state. That said you must return to the switch (using C) using a loop.

Personally, I would use while(1). That is, an infinite loop. The switch would have a case for the exit state and there I would return from the function.

You enter the loop with the initial state already set.

But what JosAH says works as well up until processing is involved with either the initial or exit state. Then you need actual cases for these states.
Jan 19 '09 #7
great to know ;) I just saw some people had written state machines without so I didnt want to learn to apply an unnecessary step.

Thanks everyone for the help, and any tips on learning optimal structure for OOP are of coarse appreciated.

Cheers
Jan 20 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Michael Foord | last post by:
#!/usr/bin/python -u # 15-09-04 # v1.0.0 # auth_example.py # A simple script manually demonstrating basic authentication. # Copyright Michael Foord # Free to use, modify and relicense. #...
9
by: Malcolm | last post by:
After some days' hard work I am now the proud possessor of an ANSI C BASIC interpreter. The question is, how is it most useful? At the moment I have a function int basic(const char *script,...
56
by: Dave Vandervies | last post by:
I just fixed a bug that some of the correctness pedants around here may find useful as ammunition. The problem was that some code would, very occasionally, die with a segmentation violation...
14
by: luis | last post by:
Are basic types (int, long, ...) objetcs or not? I read that in C# all are objects including basic types, derived from Object class. Then in msdn documentation says that boxing converts basic...
3
by: sefe dery | last post by:
hi ng, i try to create a asp.net 1.0 website on windows server 2003(Servername: ServerX) with iis 6.0. PROBLEM: The user should login with his windows credentials in basic.aspx and...
13
by: usenet | last post by:
How and where can one find out about the basics of VB/Access2003 syntax? I am a died in the wool C/C++/Java Linux/Unix programmer and I am finding it difficult to understand the program format...
10
by: trippeer | last post by:
I have the source code to an old BASIC program that a friend of mine would like to run online. I am a beginner at JS, but I think that it would be a good choice for the project. My background is in...
97
by: Master Programmer | last post by:
An friend insider told me that VB is to be killled off within 18 months. I guess this makes sence now that C# is here. I believe it and am actualy surprised they ever even included it in VS 2003 in...
111
by: Enteng | last post by:
Hi I'm thinking about learning C as my first programming language. Would you recommend it? Also how do you suggest that I learn it?What books/tutorials should I read for someone like me? Thanks...
6
by: Simon Walsh | last post by:
I'm an Electronics student in college and I'm currently working on a project. I was given a circuit diagram for my project, from which I had to design a printed circuit board to be sent off and...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.