WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Me:
Count the A's, SPACEs and -'s in each line, and in each section of each line.
Look for numerical patterns.
When you see the patterns, write down some calculations that you can turn into code.
Use lots of paper, and analyze analyze analyze. Plan plan plan.

You'll need a few loops for each line.

OK, I guess you don't have to do any of this. Just convert Lucaci's pseudo code into real code. He did the hard work for you.

Be sure to thank him.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Count the A's, SPACEs and -'s in each line, and in each section of each line.
Look for numerical patterns.
When you see the patterns, write down some calculations that you can turn into code.
Use lots of paper, and analyze analyze analyze. Plan plan plan.

You'll need a few loops for each line.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

The vertical spacing is bad, and we can't use it 'in context':
cx += testval is the way to add to cx

This thread is what prompts the request.
Normal CODE Tags are too limiting -- I didn't want to use them as a hack.

Inline CODE is still code - by definition. Spacing should be honored.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
    while(iss){
    {
        string sub;
        iss >> sub;
        cout << sub << endl;
        a=sub.length();

        index=sub.find_first_not_of("aeuio");
        cout << "first consonant:"<< sub[index]<<endl;
        harf=sub[index];
        sub.insert ( a, harf ) ;
        sub.insert (a+1, "AY"); 
        sub.erase(index,1);
        cout << "new word:" << sub << endl;

    }

This section does not do what you want. Even if it works you get
"each" ==> "eahcay"

index=sub.find_first_not_of("aeuio"); What if index is zero?

The instructions "put the first consonant to the end" does not mean the fist consonant in the word. It means if the first letter is a consonant.
each becomes "eachway" (note -- add "way" not letter+"ay"
touch becomes "ouchtay"
Also note that "this" becomes "isthay" and "straight" becomes "aightstray". It's the first consonant sound(s), not the first consonant letter

You did good outputting the strings to see what is in them. Now output the integers to see why you are getting "subscript out of range."

Additionally, do you want to insert at the end? Or is there a better way without having to know the length?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I don't really understand what's wrong with my format.

You're kidding, right? You see nothing wrong with

    variable = change *
100;                                                     
    quarters = variable /
25;                                                    
    variable = variable %
25;                                                    
    dimes = variable /
10;                                                       
    variable = variable %
10;                                                    
    nickels = variable /
5;                                                      
    pennies = variable %
5;                                                      

????

How would I test the outputs? I tried adding in cout << "\ntest: " << coinname << "\n"; replacing coinname with the proper variable.

And what did outputting variable after the line
variable = change * 100;
show you?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Depends.

What is your concept?
How do you process each of the commands in your description?

When programming, you can't just start throwing code into your file. You have to make many decisions before you code anything.

Case in point, After reading your description and making my first post, I decided this was interesting enough to try to do. In an hour I had a working program -- by following my 'design' outlined above. Granted, I've been doing this for years, but the point is I started with a design.

Since you didn't seem to like anything in what I suggested (you didn't use any of my ideas at all), you'll need to explain (design) your program given the concept you listed in your first post.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Given the lack of info in the description, I assume the program is menu driven. In other words, you just execute the menu commands after initialization in this order:

arrivals?
add
add
arrivals?
full?
check
add
add
full?
check

Is that about it?

I need some help getting started here. This is what I have written so far, can anyone point me in the right direction on this one?

It's obvious. Start writing the functions specified in the description.
In main(), test these functions as you write them.

You might want to start with a
1) the initialize method
2) print method to display all the current planes (useful for debugging)
3) add method so you can add the planes
Then test the above until they work.

Now start adding all the other functions.

bool isFull(const Airport &airport);
Why pass in the Airport? The method is part of the Airport definition. Therefore bool isFull(void); is an appropriate definition.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Time for a Moderator to weigh in. I'm raising my hand.

Gonbe: Do NOT give full working answers to questions. Guide them to writing their own solutions.

Gonbe: If you've ever gone to school you'd know that partially you do get provided examples of good practices. Generally these are subsets of bigger problems that have to be solved later but they can sometimes be a larger example too as these introduce additional complications.

You are proving our point. Notice your own wording: "examples of good practices" and "Generally these are subsets of bigger problems". How is your code an example or a subset. Isn't it full, working, hand-in code? Even by your definition it's wrong.

Gonbe: Regarding your 'point' directly, I do think YOU don't understand the purpose of homework. More precisely, you don't understand the role of these forums.

After 19 posts you know more about these forums than the rest of us? Hmmm, sounds like a bit of self-deluded arrogance to me. What makes you such an expert suddenly?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

What you are trying to do is not trivial. You need to look at the equation as a whole, not search for small parts and process piecemeal.

It might be useful to study up on Reverse Polish notation to break up the equation into individual atoms.

You can use a structure to store the atoms which would contain

1) type (whether this is an operator or a number)
Values here could be 1 for a number, -1 for an operator.

2) value (a number from the equation or a code for the operation)
Each operator (+ - * sqrt mod) has a unique value. Consider that there are operators that handle two values (* - / mod) and others that handle one (- sqrt pow).

Alternatively:

Copy the equation. 
Search for the thing you want to process.
Get the values to process.
Do the subequation.
Replace that section with the answer.  

Everything stays in the string. So if you have
10 * sqrt 25 + 3
and you want to process the sqrt, grab the sqrt 25 and replace it:

10 * sqrt 25 + 3 -- becomes
10 *       5 + 3

Note the spacing. The entire section sqrt 25 gets replaced by SPACEs and a 5.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

See comments:

  while(!(cat1->Empty()))
  {
        // process queue 1
  }

  if(cat1->Empty())    // Didn't you just empty queue 1? 
  {                    // Why do you need to test if it's empty?
     while(!(cat2->Empty()))
     {
        // process queue 2
     }
  }

I don't see a definition for nullptr. Did you define it to be FALSE or 0? Or is it a C++ definition that you are assuming to be FALSE/0?

Output values at key places in the code to see if the values are correct and the code is making the decisions you expect.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Gee. Sorry to hear that. Maybe it's on line 38. That looks suspicious.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Nope. Don't want to.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

No. They are just a different way of doing it. And you'd still need a loop anyway. IMO, your technique is just fine without the class. Although, if you notice, every one of your input sections look exactly the same:

cout << "Enter the number of XXX Dollar Bills you have: ";
cin >> bill;
cout << '\n';
bills.push_back(bill);
if (bill<0)
    error("You can't have a negative value.\n");

except for the XXX value. You could use a single loop with the XXX values in an array.

Also note that if you enter a negative number, you
1) display an error message but do not ask for a valid value
2) store and use the negative number anyway

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

can you keep it like a computer science I beginner level with the same functions and variables as i had up top

So what you want is to for him rewrite your homework for you so it looks like you wrote it, not an expert?

Wouldn't it be better if you actually wrote it, being guided by help so you'd actually learn to do it?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Why don't you try using FireFox. Its fast and sleek.

Patient: "Doctor, it hurts when I blink."
Doctor: "Don't blink."

Isn't it more like:

Person A: My car needs a brake job.
Person B: Why don't you get a new car?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Because if you deleted the post, wouldn't all the replies look a little stupid? ;-)

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

If this is for a class, I would suggest you think of something that would use the skills you've learned in class rather than trying to do something that will take a few months just to learn the basics of techniques you've never touched.

Look at something like Mastermind, Tic Tac Toe, Craps, Hangman. Something that won't take years to design and implement.

The key is design!!! Don't just sit an the computer and start programming. Sit as a desk and figure out how the game is supposed to work and figure out all the details of input, the play, the decisions, the output -- everything to make the game work. Once you figure all that out, it'll be fast and easy to actually write the code...

So don't touch the computer until you've figured out everything you need to do.

myk45 commented: very good points +5
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
nitin1 commented: walt will always be walt ;) he can never change :-D +2
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

nitin1 is correct.

With a little more detail:

Any number that starts with a zero is interpreted in base 8 (octal) rather than base 10 (decimal). Therefore your 011 is: one 8 and one 1 rather than one 10 and one 1.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

We don't write code anymore. We make you do it! ;-D

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

That completely depends on what you are trying to do there. You are asking for 2 types of functionality:
1) enter letters and use them as is
2) enter numbers and convert them to binary

Which do you want? What if you want to enter the character '6'? You can't do it. Your code only handles the number 6.

Think about it...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You've pretty much got it...

The explanation I was looking for you stepped around rather than stating directly (understandably).

When you put a char into an int (or int into double, char into double, etc) the compiler does a translation to 'make it fit'. That's also true when calling or returning from a function.
It's safe up to a point. If you put an int 130 into a char, you will lose some of the number. That's what you have to be careful about.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

i think im getting it now :) thanks for pointing it out :)

Looks like you are...

the char byte gets copied into the lowest byte of int.
....
(0--0)(0--0)(0--0)(10000001)

Good...

i dont think an integer can give 'A' output to the console... although data stored is the same...

Try it... Define a char and and int. Load 65 into both. Now output both. What happens? Why?

did i make sense?

You're doing good :)

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

from what i understand:

  1. char==1byte==8bits
    therefore, if i call 'ch' a char variable, and assign it value 5, then binary ways:

ch= 10000101 (signed negative char)

How do you get 10000101? Where did the first 1 come from? What you have is -123. Just because it's signed does not mean the first bit is 1. It just means the 1st bit is used as the sign bit.

My question was referring to what happens when you have something like

int a;
char b;
a = b;

Is this safe? What happens to the values when you assign values to a different type? This also affects:

int a = 23;
int s;
sqrt(a);

since sqrt() takes doubles, not ints. What happens to the int ?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Some things you need to figure out:

1) What happens when you pass a character variable to a function that wanted an integer?
2) What happens when you return an integer into a character variable?

Are these safe?
Do you need to convert first?

Research them...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Or you can call atoi() and not have to actually write the code. ;-)
Look it up...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

How many bytes does ip point to? None... You defined the pointers ip and op but no actual space.

You are making it too complicated. What did you read into input? At least 2 characters, and up to 40 (that is if your fgets() was right - which it isn't). So just look at the first character and you're done...

short int2shrt(void)
{
    char input[40];
    char  ip;
    short op;
    printf("enter input:\n");
    fgets(input,39,stdin);        // note the correction
    ip = input[0];                // this is the character you want
    printf("You entered %c",ip);  // remove the *
    op = ip;                      // just load it...
    printf("the output in type short is: %h",op);
}

I made minor changes to almost every line. But this is a lot closer (and easier) to what you want.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I guess it was a bad idea to ask for help here.

Actually, it wasn't. You just didn't ask one that could be answered.
I take it back. You never asked a question at all -- in any of your posts. So don't get huffy with us!

To sign off on this thread, I'll give you all a quote from my project:

And I'll finish off with a quote from the garment cleansing industry:

No tickee? No laundry!

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Reply #3

That should give us enough to play with...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Reply #1

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Use this thread to test rep

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Can someone please clear this up and state exactly what happens in the following scenarios?

Based on my tests as a moderator:

1. I click the up or down arrow without entering a comment
The post is voted up or down. No rep change

2. I click the up or down arrow after entering a comment
The comment is logged and rep is changed based on the arrow.

3. I click the gadget to the right of the comment field (in other words neither the up or down arrow) after hovering over the Up/Down arrow to change the gadget to either Up-Vote or Down-Vote.
The comment is logged and rep is changed based on the arrow that invoked the comment box. The gadget informs you which arrow is active.

Find any of my posts in the C/C++ forum and play around. If I get too much neg rep, though, your posts are in danger!!! :)
[edit]Note: Doing your business in this forum does not alter rep[/edit]

[edit2]Better yet, use this thread[/edit2]

Note to self:
3,415 Reputation Points

Last logged rep (reversed):
fdsfds — iamthwee, 2 Hours Ago

Last actual rep:
Giving you negative rep ... test — Dani, 2 Hours Ago
Thank you, I'll remember that! ;)

Reverend Jim commented: I have no idea what I am doing anymore. +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Why would the creator be important? Isn't the content the important thing? You could have saved yourself a lot of time and trouble by not vaguely reading it the first time, dontcha think? ;o)

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

So return it, don't pass it in.

You are inputting the value directly into the class variable student_name so you don't need to pass anything into the method. By passing it in, I believe you have created a local variable and bypassed the class variable.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

It's not weird at all. It's lack of understanding how scanf() works. Here's a series that explains the problems you are having. This will also help you next time you need to mix integer and character input using

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I would suggest you open your book and look at the chapter on arrays. your question is sooooo basic that it's in there.

Eagletalon commented: Correct way to assist, reference to answer and not spoon feeding, brilliant +3
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

No, but that's what 1 is -- an integer. And what you input is a character.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Look up how malloc() and free() work

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Not fair, deceptikon -- giving me rep and taking it back! Positive rep, even as a test, is a good thing! :P ;)

On a serious note, I hope you aren't planning on changing the wayt the box and arrows interract. I happen to like the way they work now.

Oh, and the comment you made was left in my list of rep even after you removed it. That might be a bug...

deceptikon commented: I'll return it to you. ;) +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

What type did you enter with scanf("%c",&option);? What's the binary value of the input?
What type did you compare with case 1:? What's the binary value of the test value?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

this is a code from the book "the C programming language" by dennis ritchie

I'm looking at the code in the book right now. Your code doesn't look like the code in the book. They wrote the code with indentation so that it's easy to follow.

Look at the big IF statement. 2/3 of the statement is good, but 1/3 is wrong (it's wrong in the book, too). What do you see that's not consisent? I velieve if you look closer, there is either an error or warning for that line.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I get a bunch of errors and dont really know what to do. Any suggestions?

Sure. Fix them. The errors tell you what line number and what the problem is, so look there and correct it.

nitin1 commented: :P +1 +2
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

but why it is necessary to have a checking crietria ? I think we just need to convey our message

ey'll shoow ewe eyo. duz ts cuvay teh msesje eym treyngg tewo siay?

np complete commented: LOL :D +0
nitin1 commented: wow! so we need to laugh ? :-o +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

He gets my sudent rate... ;o)

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Start by opening the comiler's IDE. Then add #include <iostream>. You can continue from there.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

When you want to enter a sentence ( that is spaces will be present ) , use fgets().

Don't you mean cin.getline()? This is C++...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I did not do any HW for others. He tried and need help and I get him a way to know what is his wrong. There were several mistakes in his code and I do it for him.

You said:

This is working code on Watcom C/C++

so yes, you did.
Correcting all his mistakes without pointing out what they are is doing his work.

Simply pointing out his mistakes and suggesting corrections -- no code -- is helping.

Remember, "I do it for him." is doing it for him, not letting him do it.

nitin1 commented: awesome explaination of doing homwork ;) +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Look at it this way.

A declaration is like your street address. It isn't where you live, just a reference to the location. It simply says that your place (or the variable) exists somewhere.

A definition is the house/apartment itself. It holds all your stuff -- like a variable.

You can have your address (declaration) on letters, your license, in your bank account, many places. But your house (definition) can only be in one physical place.

int x; is the definition.
x = 10 is not a definition. It's an assignment. Like buying a new chair. It just goes into the space that's defined.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You have to be able to analyze the problem and pull out its important ideas. For example:

Issue: Your fellow students need help. This is their first year in college and

Who cares. Not part of the real problem...

they need to determine how many hours they need to study to get good grades.

Here is the problem statement. It's describes what needs to be done.

Study hours per week / Grade
5 / A
4 / B
3 / C
2 / D
0 / F

Here's the data necessary to determine the answer to the above question.

The user enters either the number of hours they plan on studying per week or the grade they want based on the number of creadit hours they enter.

The inputs required to process the data above.

The program displays the user's name, number of credits, total number of study hours, and grade they should expect to receive.

Additional inputs necessary for the output of the final solution have been added. Some is just bookkeeping (name). Some is the input for the solution (study hours or grade). The rest become the calculated values (grade or study hours) depending on the input.

In this case since there are 2 possible inputs (a letter for GRADE or a number for STUDY HOURS), there are two different calculations that need to be considered. Therefore a decision needs to be made …