Infarction 503 Posting Virtuoso

Now you need to read in the file. You could probably do something along these lines:
- read in a line (I recomment using getline()
- parse that line to get the student's name.
- continue parsing to get a list of scores. Add these together, probably as you read them in.
- compare this to the total score (where are you getting that anyways?) and determine if the student passes.
- do this till you have all of the data read

Then comes the tricky part. You need to sort all the data by students' last name. It would be easiest if you kept the data in an object, but that's not necessary (just a little more hassle without). You need to sort the data by last name, and make sure you keep all associated data together as you do it. This'll be kinda tricky if you just use indepented arrays/vectors of names, scores, etc...

Then output the students info in the new sorted order. As you do this, you could keep track of the number of students, and start averaging their scores. You could also do this in separately, but why put it off till later? Anyways, after you've gone through the list of students you'll have the other statistics you need, so you can output those too.

Good luck ;)

[edit:] oh, and you seem to have missed the part about code tags. Please use them, since it preserves your code formatting …

Infarction 503 Posting Virtuoso

haha, that thing can be fun...

I don't remember how I did it, but one time I used the ??? thing and somehow got it to stabilize itself (or at least keep itself going) for over 1/2 hr... and yes, I watched it for that long... :o

Infarction 503 Posting Virtuoso

Wow, Dani, that's quite a zoo you've had... :eek:

Infarction 503 Posting Virtuoso

Wife, go get me a beer!

I'm soo gonna get flamed for that... :twisted::lol:

Infarction 503 Posting Virtuoso

Off-topic: Narue, out of curiosity, where did you get your nick?

On-topic:
Thought I'd share some pics...
pic 1 and pic 2

Anyone else want to share pics?

Infarction 503 Posting Virtuoso

Try making a vector of Tree*, and add elements which are Oak* and Elm*. Of course, this means you'll be working with pointers, but I'm assuming that you'll be fine with that...

Infarction 503 Posting Virtuoso

I think what Narue meant was, how is it not working correctly?

Infarction 503 Posting Virtuoso

Maybe I should consider myself lucky that my first impressions of Narue are from her technical posts... that said, I think a great many people, especially on the internet, fail to realize how sheltered and buttered up their lives have been. And if you can't take some [mostly] anonymous criticism or harsh words, I feel sorry for you...

Infarction 503 Posting Virtuoso

Thinking the same? Or complying with your personal ideals? I'm sure I don't fit either of those, but I'd like to think that I'm still a good person ;)

Infarction 503 Posting Virtuoso

There are still many cases where speed is more important than the programmer's time and salary. embedded programs for example require fastest running code possible, so programmer's can not do sloppy or inefficient work there.

Embedded systems is a great example. Huge scale applications are as well, e.g. Amazon.com or Google. Obviously, they have to achieve a balance of maintainability and performance, but they can't just throw resources around like it's no big deal. The amount of resources they consume already is, at least to me, amazing, yet they're still growing fairly rapidly, and always worrying about efficiency.

Infarction 503 Posting Virtuoso

I'm in the U district (being a student still), and... well... I don't really know how you'd measure cost of living. And no, it's not raining at the moment, though it is a typical overcast day.

Infarction 503 Posting Virtuoso

all folks skid or guiltily enslave friends

Infarction 503 Posting Virtuoso

I am really glad that the people who strove their entire life, being kind and compassionate to others, just for the betterment of this world are no longer here to read your post.

I have to agree with Narue unfortunately. The world is not a nice place. Even if everyone acted according to their own ideals it wouldn't be a nice place. If you were to force your own ideals onto everyone else and make them act accordingly, the world might be a nice place, except for your action. IMHO certain people deserve to be treated nicely, and others not so much. And I act accordingly.

Infarction 503 Posting Virtuoso

I fail to follow the logic of [tex]girl \rightarrow favorite\ pet = dog[/tex]... :p

I'm not much into pets... my parents have a pair of Jack Russell Terriers, very cute, very very hyper, but I just didn't like the inconvenience. I do enjoy other people's pets though :p

Infarction 503 Posting Virtuoso

As expected from a true anime phreak.
Ne ne, Infarction nou baka ( hope this translates to Infraction is baka ;))

The Japanese is only partly from anime. And a very small part at that. I studied it last year as an elective as well, and I was disappointed that I couldn't squeeze it in this year. :sad:

~s.o.s~ は酷いですよ :p

PS - it's "no" rather than "nou"

Infarction 503 Posting Virtuoso

>In life you either contribute to purity or decay
You should be a politician. Oh, by the way, your statement is a logical fallacy. ;)

Sounds perfect for the job ;)

Infarction 503 Posting Virtuoso

Logical arguments are most difficult to argue with

Infarction 503 Posting Virtuoso

Can you speak Russian, Polish or Greek?.......Justine

Unfortunately not. I know how to say "no" in Russian, and if I tried hard I might remember how to sing Happy Birthday in Polish, but I learned that from a teacher in elementary school. I do speak Spanish and a small amount of Japanese though...

Infarction 503 Posting Virtuoso

Seems there's as many people from the US as not in this thread, so what the hay... I've lived in the greater Seattle area all my life, and I guess I'm one of those "melting pot" kinda guys as well... culturally I'm a mix of Irish, Scots, Welsh, English, Greek, Polish, Russian, and I think one or two others... :confused:

And after reading this thread, I'm starving :p

Infarction 503 Posting Virtuoso

Polar regions -> ice

Infarction 503 Posting Virtuoso

Linux distro -> Penguin

Infarction 503 Posting Virtuoso

BTW, I must admit that this code is really crappy. Today, a developers time is MORE valuable than memory or CPU processing speed; thus, always write easy to read maintainable code!

Unfortunately, developers still do have to worry to some extent about CPU and memory usage. Thinks like memory leaks pop up, even if the code is easy to read and/or maintain. ;)

(you forgot to free() what you allocated)

Infarction 503 Posting Virtuoso

oops

Infarction 503 Posting Virtuoso

Saying older is pretty much realative. Which anime series do you consider as older. BTW have seen a lot to even keep count or track...
Drats...we have got too many Jap speaking people here....first Miss Narue and then you..maybe shouldn't have gone out to be extra smart.

I know I sometimes can be a big baka. :D

True, it is relative. I usually consider things 5 years old to be "older" series. And it is pretty hard to keep track of everything one has seen, but somehow I think I've managed to get almost all of mine (though the list still somewhat short)...

>Oh, and your romanji is off...
That would be romaji or roumaji, or equivalents depending on your favorite romanization system. ;)

Ouch. ~s.o.s~ was right ;)

Infarction 503 Posting Virtuoso

Japanese cartoons, you name it.

Some of the good ones which I have seen:
...

And btw I don't believe cartoons are for kids, watching and being informed about cartoons is like a hobby for me and I don't think hobbies are meant only for kids.

aarigato all of you and this topic is really sugoy.
:D

Looks like you've mainly seen a lot of newer stuff... have you watched many older series?

And I do agree, cartoons can be produced for an older audience. Unfortunately, I don't think many American cartoon series do that without resorting to crude humor...

Oh, and your romanji is off... it's arigatou or arigatoo and sugoi :p

Infarction 503 Posting Virtuoso

I tend to favor odd numbers... but not odd in the sense of 2n+1, but rather numbers like pi, phi, e, sqrt(2), 1/7 (don't ask why), and i... the last of which is really fun to italicize in bbcode... :p

and of course, one of my favorite formulas would have to be:
[tex]e^{i\pi} + 1 = 0[/tex]
though it's also fun to toy around with
[tex]e^{\frac{i\pi}{2}} = i[/tex]

Infarction 503 Posting Virtuoso

Gotta agree with sharky on 5 and 6, and a large part of 7... I've spent (and will likely continue to spend) waaay too much time watching anime... :eek:

Infarction 503 Posting Virtuoso

I usually get 8 hrs of rack time... almost always, even... doesn't always add up to 8 hrs of sleep though ;)

Infarction 503 Posting Virtuoso

A seg fault typically refers to when you start touching memory you shouldn't be. As Niek mentioned, this often occurs when an invalid index into an array. It also happens when using uninitialized pointers, or pointers which have already had their data deleted or freed.

Infarction 503 Posting Virtuoso

Working with these lists of number is most easily done with an array. I think (if I understand this assignment correctly) that it could be done without them, but in a very cumbersome, roundabout manner. Here's 2 ways to do this:

- Use arrays. Take your input, put all of the scores into one array and all of the weights into another. Although you've demonstrated a disinterest in learning new things, you might want to look into using the std::vector class, which is essentially a dynamically sized array. After you've gotten all the input, you can calculate the sum of each list, and do the math you need to do with that. You can also print the lists and results from the array's you have and the math you've just done. That's about it.

- If you truly refuse to use arrays, you can input the data in pairs (e.g. "Enter a score: " followed by "Now enter a weight: "). For each one, add it to a string for that row, that is, one for scores and one for weights. Also add the value to a sum for each row. At the end you'll still have the sums and the strings you need to output, and you can proceed to do whatever math you need to do. This is IMHO a less elegant solution, but should still get the job done...

Infarction 503 Posting Virtuoso

& can be used to denote a reference or to get the address of a variable, (and also as a bitwise operator). When used at the declaration (e.g. as Node*&) it is the first, and when used in a non-declaration and preceeding a single variable, it is to get the address. When it is between two vars, e.g. a & b it is performing a bitwise-and operation between the two.

Infarction 503 Posting Virtuoso

so, here's the output I get from running it (I made a few changes to the code, but nothing to affect the logic, and the lines starting with $ are where I start the program):

$ ./a.out 
Please choose your gender(M/F). M
You have chosen a male character. 
Please choose your class.(Mage,Fighter,Archer.[M,F,A]) F
You have chosen the Fighter.
 $ ./a.out 
Please choose your gender(M/F). F
You have chosen a female character.
 Please choose your class.(Mage,Fighter,Archer.[M,F,A]) A
You have chosen the Archer.

Is this output somehow incorrect?

And if you're wondering what changes I made to the source...
- I renamed the headers to <iostream> and <iomanip>, and also added the line using namespace std; after all the #includes
- I changed main() to int main() - I removed the system("pause") because it's not portable (mainly because it doesn't work on my computer)

John A commented: Good job --joeprogrammer +3
Infarction 503 Posting Virtuoso

What exactly is the problem you're having? Unfortunately, "please help" does not give us enough information to actually help.

That said, a few observations:
- you're missing the closing brace ('}') for main()
- when you pass the array to GetInfo, you should also pass the size of the array as a second parameter, so that you can avoid overflowing your array. While this doesn't allow the user to input data "as long as they want," it does keep your program from crashing in the event that they want to input more than you expect.
- for saleprice(), you can just return price * 0.9 .
- just looking at the instructions again, you should probably rename GetInfo to InputData or somesuch, since you also need a function to print the information contained in the array.

Just a li'l feedback for now, but specify a problem and we'll see about fixing it... ;)

PS - please use [ code] tags when you post your code, as it makes it a lot easier to read...

Infarction 503 Posting Virtuoso

um... what is different between being male and female, except for the value of gender? I don't see what the problem is...

Infarction 503 Posting Virtuoso

I'm surprised your teacher isn't allowing for lazy deletion. That said, here's one method (I don't remember the best way though) for deleting from a BST:

Find the node to be deleted. From there you have two ways to get it's replacement:
- go left one node, then right all the way to the rightmost leaf of that subtree. That node will have the property of being greater than everything above or to the left of it, up until the deleted node. It is also less than everything to the right of the deleted node. Hence, a suitable replacement. Remove it from its leaf position and put it in the deleted node's place.
- similarly, you can go right one node, then left recursively to a leaf. Same properties will apply, though mirrored.

This might end up a little messy moving all the pointers around, but it's a conceptually easy way to find a replacement for the deleted node... HTH ;)

stymiee commented: Great post - stymiee +2
Infarction 503 Posting Virtuoso

How are you defining a palindrome? Obviously, it means that the string is symmetric about its middle, but how do you handle non-alphabetic characters? For instance, if you check that every char is between 'a' and 'z', you'll miss out on capital letters (easily resolved with the tolower(char) function found in <cctype> ), but you also miss numbers and special characters. The last of those is probably good to skip, but numbers you may want to keep (you do have them in your test file, afterall).

If I were to write this, I would implement a loop which kept 2 indices into inputString. One would start from the back, and one from the front. For each one, I would find the first alphanumeric value ( isalnum(char) ) that hasn't been checked. Compare the two and either return false if they don't match or continue checking until the two indices cross each other. If they do cross, return true.

Oh, before I forget: isalpha and isalnum both return non-zero (i.e. true) if the given char is a letter or letter-or-number, respectively.

Infarction 503 Posting Virtuoso

while I'm at it, for the #ifndef stuff, should I be putting the class name in there instead of a TGA_H? I thought I had seen it done that way before...

Leave it as TGA_H. The #ifndef followed by the #define are a way to tag your file uniquely so that it never gets #included more than once (which would cause multiple-definition hell). If you use an IDE which autogenerates those lines (old versions of VC++ used to, but I think newer ones use the compiler-specific #pragma once ) you'd see pretty much a random string so there would never be issues with another file having the same tag as yours.

Infarction 503 Posting Virtuoso

I presume SOS may not have the fast internet access we have here in USA. 50Mg can be a lot for slow dial-up modems or whatever people in India use.

LOL here in the USA we have slow internet connections... relatively speaking of course... :rolleyes:

Infarction 503 Posting Virtuoso

slight correction to the page ~s.o.s~ linked to: strstr returns a char*, not a char. They did mention that in the description, but it was incorrect in the function declaration.

Infarction 503 Posting Virtuoso

Haha, anyone who can recognize BPS deserves a hand... and your ava isn't bad either ;)

Infarction 503 Posting Virtuoso

The #include "myheader.h" will essentially paste the contents of myheader.h into the top of whatever file it is #included into. So it'll be comiled just fine. In order to get the .cpp file compiled, you can just specify it first on the command line, e.g.

$ g++ myheader.cpp main.cpp

and the linker should take care of everything... I think... (been a li'l while...)

FireSBurnsmuP commented: Like I said, you might have saved my life. +1
Infarction 503 Posting Virtuoso

When you run a program, the program starts with the main() function by definition. You need a main() somewhere in your project, and whatever file contains main() should be the one you compile to create your executable. You can just put main in another file (e.g. main.cpp) and that way keep your implementation stuff separate.

Oh, and when I start my computer, I use the power button, not a .o file :lol:

Infarction 503 Posting Virtuoso

You can just index the string like an array.

if(mystring[i] == 'A')
  mystring[i] = 'G';

Note that this is done using the character values (e.g. single quotes), and can only be used when replacing a single character at a time.

Infarction 503 Posting Virtuoso

You'll need to write a parser for the file. For instance, if you read the first line "Year: 2005" you know the following set if or that year. The next line has has "Number of Employees: n" (let n be a number), so you know that you'll have that much data. The line after "Number of Employees" looks to be a header, so you can throw it out. Then you iterate n times to get your data, putting it into whatever data structure you deem worthy. At that point the next line will probably have another "Year: yyyy" (yyyy being whatever year it is) and you just repeat the process until either the end of the file or till the data is incorrectly formatted. I'm assuming the latter won't occur ;)

Infarction 503 Posting Virtuoso

1) You need to be saving your random letters to sequence, not changing letters. Like this:

for(int index=0; index<20; index++) 
            {
               random_integer = lowest+int(range*rand()/(RAND_MAX + 1.0));       
               random_integer = rand() % 4;                                    
               sequence += letters[random_integer];
               cout << sequence << endl; // this should probably be out of the loop though
           }

2) Loop through the string, and if it has a 'A', just replace it with a 'G'.

3) with 2 options, an if statement should be fine. You could also use a switch.

BTW, with the line if(answer = Y) , you should be using if(answer == 'Y') , so that you compare (rather than assign) to the value of the character Y (rather than the non-existant variable named Y). You should also consider comparing to lowercase 'y'.

Infarction 503 Posting Virtuoso

Determining if it's the best depends on how you measure. Since it only reads the array once, my solution is very close to, if not, optimal in terms of performance. Using lots of if-else is not necessarily a bad thing compared to the tradeoff of, say, reading the whole array for each value you need in the result.

Though it might be a little more difficult, you could try keeping the small and large sublists (of 3 values) sorted, so you only have to compare to the largest one in the small list and to the smallest one in the large list. It would reduce the number of if-else's you had, but would require more overhead to track which one to compare to.

Infarction 503 Posting Virtuoso

The most basic way to keep them together is to do as ~s.o.s~ did by having them ordered the same, so that a given index into one array will correspond to the same index into the other array. If you're just starting in C, this is probably the best way to go for now...

Infarction 503 Posting Virtuoso

How would you solve if it you were doing it by hand? A basic process might go something like this:

- Keep a set of 3 markers for each of high and low.
- Go over the array(s), and at each new value:
  - Determine if the new value fits in the set of lowest or highest
    - If it does, replace the one that gets bumped with the new value

Once you've traversed the array(s) once, you'll have your answer. ;)

You may want to consider how to treat duplicate values (i.e. can duplicates be stored more than once in the result lists or should you find unique low/high values).

Infarction 503 Posting Virtuoso

Indentation (and whitespace in general) is important for anyone who ends up reading the code. That includes the person who wrote it.
The readability of properly indented code is very much greater than unformatted code.

Infarction 503 Posting Virtuoso

I find IDEs to be helpful for larger projects, but if it's just a few files I use a text editor (vim). IMHO, everyone should start with a text editor though, and move to an IDE once they're comfortable with the language.