siddhant3s 1,429 Practically a Posting Shark

To the OP:
As it has been said: Programming is an Art.
Some have god gifted talent in programming. Others develop their talent by practicing more problems.
It is simply not possible for us to solve this problem (of having non-logic mind in programming.)

siddhant3s 1,429 Practically a Posting Shark

I think the book is pretty much fun.
Though being a Linux(which it originated from MINIX which in turn originated from UNIX) user, I have my full sympathy and support over UNIX,

But the book is really hilarious. Thats it. Nothing more.

UNIX has changed the meaning of OS. No doubt.

Moderators: Don't you think this thread will be more good for the Geek Lounge.

[edit] : Anyone interested in reading book, is freely available for download:http://www.simson.net/ref/ugh.pdf

siddhant3s 1,429 Practically a Posting Shark

Who told you to use cin.getline, didn't you knew cin.getline is only to fetch cstrings?

You should have used simple cin>> statement to read the data.

siddhant3s 1,429 Practically a Posting Shark

Read the prototype of getline
The first argument should be a char array ( a cstring).
Tell us what is the structure of student.

siddhant3s 1,429 Practically a Posting Shark

OK, fine. It's generally the last thing a professional programmer would do.

Peeking is generally used for OS level programming when you need to do things outside the ordinary. Reading the character and processing it is ordinary. And this task certainly can be done easily using the ordinary techniques.

You didn't satisfied me atleast. It was better if you had given a citation or some reference. If so however it is your personal advice, I respect. I may follow it too.
Anyways, Tux didn't deserved a Anti-reputation for this.

siddhant3s 1,429 Practically a Posting Shark

>>My ghod! Don't use cin.peek()!
Why? You have anything to support your argument?

>>Read the line as text and process it.
OP would have to force to do this if the exit code was not a single charachter but a string (perhaps like "exit" or "bye").
When he needs to peek only one character, Tell me how it is bad.

siddhant3s 1,429 Practically a Posting Shark

>> cout << (dynamic_cast <Person*>(p))->getAverage(); Look what are you doing. You are casting a Person pointer with Person only. What is the effect?

change it to cout << (dynamic_cast <Student*>(p))->getAverage();

siddhant3s 1,429 Practically a Posting Shark

You are not using the peek properly: The code should be like this

int main()
{
    int num1, num2;
    char chr;

    cout<<"Enter an integer to start:  ";


    while (cin.peek()!='|')
    {


        cin>>num1>>num2;

        cout<<num1<<' '<<num2;
       //do things with num1 or num2
    }

    cout<<"Bye!\n";

}
siddhant3s 1,429 Practically a Posting Shark

>>Didn't even think about that! Thanks!
If your problem is solved, mark the thread as Solved so that no other person scratches head on your problem.

siddhant3s 1,429 Practically a Posting Shark

Use strcpy() defined in <cstring>

char* extract_key( char* buf, char* find_this_key )

strcpy(color_of_car, extract_key(buf, "car_color") );
strcpy(brand_of_car, extract_key(buf, "car_maker") );
siddhant3s 1,429 Practically a Posting Shark

show the code of extract_key

siddhant3s 1,429 Practically a Posting Shark

>>See my delima ? checkSum is a char[5], and the sprintf format suggests that it will insert a value that is 4 in length, left padded with 0's and will be X hex format ?

There is no need to worry. The checkSum will be filled till the fourth subscript and the fifth subscript will be null character.
In C-strings, if you defined the array with char arr[k] then string you can store in arr should be of maximum length k-1 since the last element should be a null character '\0'

After the execution of the sprintf the checkSum will look like this:

checkSum:
index:     |  0  |  1  |  2  |  3  |  4   |
values:    |  0  |  0  |  7  |  B  | '\0' |
siddhant3s 1,429 Practically a Posting Shark

Read: http://www.cplusplus.com/reference/clibrary/cstdio/sprintf/

>>Can someone tell me what happens to checkSum with this sprintf method
checkSum is a c-string( array of chars) its value is set by Total's hex value converted to c-string.
In short, after this command, Total will be converted into its hex and in form of a string and will be stored in checksum.

siddhant3s 1,429 Practically a Posting Shark

i dont know, you may be right.... BUT

it's generally a Bad Idea for a first year programming student to tell the professor the fundamental premise of his assignment is flawed.

unless that student is prepared to deliver a bulletproof example and orally defend it against close scrutiny.


.

LOL, I am not telling him to shut the professors mouth but informing him.
But look at the interface. If the professor meant that this interface should be implementation for the std::string, it is a tough assignment for the beginner.
It may be possible that profesor has given the OP to design a 'home made' string class which should have a member called swap(), then it makes sense and OP is actually on the right track.

siddhant3s 1,429 Practically a Posting Shark

>>// With the "(" and ")" added i guess it should copy value like pointers do
Even if you didn't it would still be same.

To the OP:
The "Test" of you professor is perhaps not good. The interface given by him is already implemented as std::swap
What sky diploma told you must be true. That is, you should create a function, take two strings( by reference) and swap them(as he told you in post #2).

siddhant3s 1,429 Practically a Posting Shark

so the problem is, I don't know how to fill it with data.
I've seen that you could use myMap.insert<pair<some stuff...
but i dont know how or if you can use that on maps of maps.

I don't know why you created maps of maps. maps of pair would have been the right data structure.

int main()
{
    std::map<std::string, std::pair<int,int> > M;
    M[".cpp"].first=5;
    M[".cpp"].second=124255;

}

As the Dragon said, you cannot sort map actually.
If you had a bijection between the key and the value ( in simple terms it means that no two keys should have the same value), the answer was indeed simple:
You would have created another map with key as filesize and value as Ext. but in this case this cannot be done. Because two extensions can have similar filesize, and the primary condition to map is that the key should be unique.

The solution can possibly using std::multimap:
You should perhaps create a multimap with key as filesize and Ext ( multimap has two keys). Now insert the elements from the map to multimap and it will come sorted.

The efficiency issue is definitely a problem. If I were you, and knew that I would be needing to sort this things, I would not opted for a map in the first place.
I would use a struct and create a vector of that struct. Then do a std::sort() wherein I …

siddhant3s 1,429 Practically a Posting Shark

you have forgot :

using namespace std;

right after the

#include <...>

try this, for me its working fine,
for VS and for dev .

I already told the OP about this in my first post (post #3).
Also, using namespace std; is not always a good idea. Learn why. You may like to read the following links:
http://www.parashift.com/c++-faq-lite/coding-standards.html#faq-27.5
http://www.daniweb.com/forums/post849155.html#4

siddhant3s 1,429 Practically a Posting Shark

>>and it's sort of homework, I guess?
Are you asking me that? You told me it was a project.
>>I'm VERY new to C++, I've only been doing it for about 5 weeks or more so STL isn't something I know anything about.
Exactly THIS is the problem of the (so called)C++ programmer and the (so called) instructors, they tend to think that STL should be taught the the end of the course as it is a BIG thing. The result is that the students practice a lot of non-STL codes and they thus do not use STL in their future projects.
I am not blaming it on you, but nearly everyone.
I really liked the teaching methodology of Andrew Koenig and Barbara E. Moo (author: Accelerated C++
They have, from the beginning, made students comfortable with the use of Standard library, and then in the later chapters they teach actually how these things work.


Now regarding the problem:
You have just made selectionSort2 maybe correctly but it is unlikely to work. Why? Because it just sorts the GPA array on the basis of ascending GPA but you didn't sort the corresponding First Name and Last name!!
Consider the data you posted in the first post. Your current program will do something like this:
Johnson Jim 3.00
Smith Mike3.25
Jones Cynthia 3.50
Martin Lake 3.75
Gavrylyako Olga 3.99
Brown Jim 4.00

siddhant3s 1,429 Practically a Posting Shark

Not in my world. Instructors teach programming and use the language as a tool. At least they did in my day. Maybe they don't today -- which is why there are so few real programmers today, eh? Just coders who can't figure out why things work..

Yo champ! I am in your city this time. There are hardly any good programmers right here in this world.
That's why I liked the TAOCP. Knuth uses a assembly language, thats awesome considering that he is not bloating us with the 'features' of the high level programming languages not taking side of any particular language.
I rather conclude else making this thread dirty. This is my last post on this thread regarding. Any further criticism is addressed to my Inbox
This is a C++ forum ( seems to me atleast). So I have full right to suggest and promote the use of STL for the 'project doers'. Had he told me that it is a HW, I would myself encouraged him to learn from it.
Of course you've(waltP) passed a good amount of your life here on this forum ( considering the BIG number of posts you have) but really I don't consider. What I consider is that you post good. You do good. And are sensible. (luckily you qualifies) so Hats of to you.
Ffor me, every thread is a isolated entity.:)

I really get annoyed when the OP is not there to care care of …

siddhant3s 1,429 Practically a Posting Shark

>>And using these things nullify the learning process on how these things work -- the instructor is obviously trying to teach them to understand techniques

Well, I never thought it is a homework. The OP never mentioned. He told it is some kind of his project.
And besides, considering that it is a project, rather than a HW, I think STL is just the tool one should be equipped with.
I see a lot of (so-called-)c++ programmers not using standard library and making their program just less efficient.

Also, if they are having a course on C++, the instructor is expected to teach the language rather than programming. These are off course two different things.

siddhant3s 1,429 Practically a Posting Shark

Telling the compiler that T::Baz is a type (as far as meep is concerned) is not the error. In the given example, that is actually what we want. The logic error here (when typename is in play) is that Bar misdefines Baz as an object and not a type.

If writing the above, you are saying that the error is not while uncommenting the typename but actually when you instantiate the template with Bar, you are right.
The error is sure in Bar. But the logical error here is off course that we are telling the compiler that T::Baz is the type while it is not.

>>I know. I was just posting a runnable (or not) example of what she said.
I appreciate your efforts from my heart and soul.

siddhant3s 1,429 Practically a Posting Shark

Making p a shadow of an int p sneaks the error past the compiler in your example.

//    typename  // Compiles with logic error if commented out`

end quote.

If you uncomment the typename, you are intentionally telling compiler that T::Baz is a type which is, off course logically wrong.

This was exactly Narue point.
That if suppose there was a global variable p somewhere defined. And you wrote the code without typename. Then, the compiler will compile the code, but your program will not as you wanted. So, as the saying goes, sooner you detect error, the better.

There is a section about this in Scot Mayers Effective C++ Item 42.

siddhant3s 1,429 Practically a Posting Shark

This is what I always say: Use the standard library for the standard jobs.
If I assume you are familiar with std::vectors, std::maps, std::sort, there is no reason not to use them.
1.Create a std::map of <string,double>
2.Transverse the file and store the GPA of the particular name in the std::map and also store the list of name in a vector of string
3.std::sort the std::vector of names
4.Output the std::map according in the order of the vector by statement like

for(std::vector<std::string>::iterator i=name_vector.begin() ; 
i != name_vector.end() ; ++i)
std::cout<<the_map_used[*i] <<std::enl;

It would result more efficient and small code.
If you don't know how to use STL, better learn it now. You will have to learn it sooner or later.

siddhant3s 1,429 Practically a Posting Shark

Considering that you have already have defined LinkedList::getPoly(int n)
Your operator[] should look like this.

Polynomial& Database::operator[] (int n)
{
	return getPoly(n);
}
siddhant3s 1,429 Practically a Posting Shark

>>Btw. in your for loop you don't have to test all the way to x. It is sufficient to test just to the square of x.
He meant the square-root and not the square of x. ( must be a typo)

To the OP,
The suggestion of ddanbe is the most valuable here. Read it thoroughly.
As you told ( and we fully agree) you are beginner in C++. Also, the problem which you are doing is very popular and standard. I would suggest you to look a good code that determines if a number is prime or not and learn from it.
This advice would not be given to one who had not tried. As you did, and are nearly on the right track, you should perhaps study someones code.

Regarding the main() function, why are printing even those number which are not prime? You should check if a number is prime or not ( by using the function you wrote) and print it only if it is prime, else don't

ddanbe commented: Nice posting! +4
siddhant3s 1,429 Practically a Posting Shark

>>I originally wanted it to stop after every 12 lines of output
Your condition is wrong.
Basically you want to stop at every multiple of 12. that is when a is 12,24,36...
That is a divided by 12 should yield no remainder.
So change your condiditon to :

if(a %12==0)
siddhant3s 1,429 Practically a Posting Shark

Read my post ( #4)
I told you that the header file is <cstdlib> and not <stdlib>

siddhant3s 1,429 Practically a Posting Shark

>>Same for #include<stdlib.h>
The standard file for the old stdlib.h is <cstdlib>

siddhant3s 1,429 Practically a Posting Shark

You have to prefix std:: before ofstream, as in

std::ofstream myfile;

>>f:\sp\vctools\icrt_bld\self_x86\crt\src\open.c
Is this your source file?
This is a .C file. Make it .CPP This may fix your problem.
Some implementation (particularly on windows) wants your source file of C++ to end with .cpp

siddhant3s 1,429 Practically a Posting Shark

I have not seen your code thoroghly but the immediate thing I would like to point out it this: if (a = months+12){ as you may see you have used a = rather than ==. In c++( and even in C) = will always evaluate true. To test for a condition == should be used.
So change it too ==.

siddhant3s 1,429 Practically a Posting Shark

>>Start learning C, then you can go into the object oriented parts of C++
Bad advice. Will turn into the "I-write-c++-code-but-am-actually-a-C-programmer".
If you want to learn C++. Learn C++. Don't learn C. Rather it can perhaps spoil your C++.
C++ and C are two different languages.
Read the following thread:http://www.daniweb.com/forums/post818590.html#post818590

Tutorials are rarely good-written for C++. One of the correct C++ tut is http://home.no.net/dubjai/win32cpptut/html/ . Its not easy, Its not maybe good, but it is CORRECT.

I would suggest to get a book rather than relying on tutorials.
If you have money, buy Accelerated C++ by Andrew Koenig and Barbara E. Moo which in my opinion is the best book which keeps you away from the "dirt" spread on internet about C++. It, from the beginning teaches you pure and perfect C++. A highly recommended book if you want to learn C++.
If you don't have money, go for Thinking In C++ by Bruce Eckel freely available online on his home page which is itself a piece of art. Great books both of them.

My only request is don't start by the learning-C-and-spoiling-C++ approach. It will eventually lead you in bad C++ programming.

siddhant3s 1,429 Practically a Posting Shark

any ideas?? here is the overloading code

Well look at your code. You are unnecessarily using getline() when you should have been using cin.
Tell me if your user will enter values which will have spaces like "2 / 7" ? If no, then why are you using getline() ?
The harm in using getline is worth considering.
Suppose you issue a statement:

cin >> r1 >> r2;

This will cause the execution of the code you wrote. The compiler will issue the call for the function operator>>(cin,r1) which you overloaded. The compiler will issue another call the the same function with the first parameter as the return value of the first function call and the second parameter as r2.
Let us check the first function call. The compiler sees a getline. So it accepts a line from user. Now suppose the user entered: 2/1 3/4. Hence readLn will have value "2/1 3/4" as a string.
Now you have replaced the first / with a space. So your readLn looks like "2 1 3/4"
And now, using string streams you will set the numerator as 2 and denominator as 1. Good. But the 3/4 is simply LOST.
So this actually will not do what you wanted.
If instead you have been using cin(here in) in the 3rd line of your function like :

    string readLn;
    in>>readLn;

Things would have work more smoothly.

siddhant3s 1,429 Practically a Posting Shark

>>now where exactly should I include these in my class?
As these are the definitions of your class, it can either go right after where you defined the class:

class Rational
{
   private:
        // private members declaration
    public:
        //public members declaration
};

Rational Rational::addition(Rational a, Rational b){
	Rational result = Rational((a.numerator()*b.denominator() + b.numerator()*a.denominator()), a.denominator()*b.denominator());
	return result;
}
Rational Rational::subtraction(Rational a, Rational b){
//definition
}
//so on

>>You aren't overloading any operators in this way ..
You're right.

siddhant3s 1,429 Practically a Posting Shark

daviddoria, read this http://www.parashift.com/c++-faq-lite/coding-standards.html#faq-27.5
Perhaps this would convince you if John is not able to.

Salem commented: A link of required reading for all aspiring C++ programmers. +29
tux4life commented: Nice FAQ ! +1
siddhant3s 1,429 Practically a Posting Shark

I don't think the code is C++.
I request the MODerators to move the thread to C. I infer no reason for this thread not to be in C forum. It qualifies to be in C forums more than C++ forums

>>as the code you posted is compiling with me ...
May be(perhaps the OP and you are on same implementation) but the code is HIGHLY non-portable and like I said, is non-C++

siddhant3s 1,429 Practically a Posting Shark

There is no return statement in squared_digit_length.

siddhant3s 1,429 Practically a Posting Shark

You can by using vitualness but don't expect much.
Read about virtual functions and virtual classes. http://www.parashift.com/c++-faq-lite/virtual-functions.html

siddhant3s 1,429 Practically a Posting Shark

>>Also we all know the best password is ****************
I doubt it. Best password? When I type this password in the Google Signup page, it tells me the password strength is "Fair".
Also, if there was a "Best" Password, most people will try to keep it. And thus it becomes a worst password.

If you were kidding, I am really laughing, and my stomach is aching.

siddhant3s 1,429 Practically a Posting Shark
for (int day = 1;day <= days;day++)
    {
// I just declared a new var to avoid calling pow two times
        int current= pow(day-1,2.0)+1;
        total = total + current;
        cout << "Day: " << day << " Daily Salary " << current << " Total: " << total << endl;
    }

Giving the following output:

Day: 1 Daily Salary 1 Total: 1
Day: 2 Daily Salary 2 Total: 3
Day: 3 Daily Salary 5 Total: 8
Day: 4 Daily Salary 10 Total: 18
Day: 5 Daily Salary 17 Total: 35

siddhant3s 1,429 Practically a Posting Shark

>>please, if i could send you my code, is there anyway u would be able to help me. thanks for your response...
What the ____?
Narue has already given you the standard c++ code. What else you can expect as 'help'.


>>what better protection than allowing a backspace as part of your password. you may have just come up with a stronger security system.
I disagree. There is thin line between comfortability and security. If I was a user, and I knew that I could not use backspace to erase the last mis-typed character I entered, I would count the software as non-user-friendly

siddhant3s 1,429 Practically a Posting Shark

>>You are missing a '{' between these lines.
He is actually misplacing '{'.
The defination of function in C++ is :

<return_type>     <function_name>([parameteres])
{
    //codes
}

rather than

{
<return_type>     <function_name>([parameteres])

    //codes
}

So make your definition as:

double taxAmount(double taxRate, int perExempt, int numberofPeople, double taxRate)
{
    //codes
}
siddhant3s 1,429 Practically a Posting Shark

Well, the therad is burnt now.
The solution has been pointed by s.o.s ( sorry I am not putting those tildes).
Tylor Theorm will come handy to you for all this 'magical' function.
you could even calculate sin,cos,tan, etc etc.
But this is not the correct way to learn programming. You would be learning 'implementation of mathematical theorems in a computer program".!!

siddhant3s 1,429 Practically a Posting Shark

Comment on Orignal Post:
When defiing an array in C++: A[n] , the subscript n can go from 0 to n-1
Both the OP and Ancient have not considered this. You have defined array as: A[3] but you are using n from 0 to 3

>>is it possible to put a constructor into an array?
I don't know what this sentence means, but it gives me a hint that the OP is trying to say if he can code the constructor to initialize the array? Yes, he can.

IMHO, you should retain your latest code intact, its fine according to me except that you should move the definition of the array, on line 21 inside the function exchange since you don't need that array outside that function.

siddhant3s 1,429 Practically a Posting Shark

>>I really enjoy GTK+/gtkmm. Lots of demos and documentation.

True. I too use GTK+ as for the same reason that it has loads of documentation.
But warn you, GTK+ don't go so 'native' on windows.
Anyways, If I got to choose form wxWidget or QT I will choose wxWidget any day.
Another point to be noted ( as mentioned by scru) is that this question has lost its bones. It qualifies to be a FAQ. The OP should use a search engine before questing.
Again, as I always those four magical words: Google is your friend.:)

siddhant3s 1,429 Practically a Posting Shark

My appoligies to the OP to divert the topic.
As for the FixName:
First of all you don't need to concatenate the comma but a space.( as per your assignment) as you have to fix it to firstname lastname rather than firstname,lastname
so change the line 9
Next:
Just capatalize n[0] and n[1+strchr(n,' ')] I hope you got why?

siddhant3s 1,429 Practically a Posting Shark

>>Here is where I am at with the code:
It would be better for you to follow the instruction strictly:

If the name is in the lastname, firstname format, then it needs to be changed to the firstname lastname format. To do this:

* Copy the firstname to a temporary string
* Add a space to the end of the temporary string
* Add the last name to the end of the temporary string
* Add spaces to the end of the temporary string until it is 15 characters long.
* Copy the temporary string into the passed in string argument

At this point, the name should be in the firstname lastname format. All that remains is to make sure the first letter of each name is upper case and that the others are lower case.

So first check if the string contains a ',' comma. Which can be done by modifying the line 9 to 12 So start you function by line 9 with the following algo in mind:

To Check if the string S contain a comma:
1.[initialization] Set k to 0
2.[Checking comma] Check if the the character at k S[k] is a comma? If yes: The string has a comma. If no: set k to k+1
3.[Checked all?] Determine if you have checked all the characters? If yes: the string have no comma, if no go to next step.
4.[Repeat] Go to step 2 again.

One point to note is …

siddhant3s 1,429 Practically a Posting Shark

Someone said that a program is algorithm+data structures.
Ancient has given you the algorithm. I would like to recommend a data structure:map to store the number of occurrence of each vowel.

siddhant3s 1,429 Practically a Posting Shark

>>If I could write it, I wouldn't be asking for help.
This doesn't work this way. Ancient Dragon wanted you to tell that you need to give more detail and the account of the effort you put in.
Also, everyone is supposed to read the Sticky thread:http://www.daniweb.com/forums/thread78223.html and also the Announcement: http://www.daniweb.com/forums/announcement8-2.html

Moreover, you are suppose to put your code in the code tags.

Now as far as your problem is concerned:
You need to get some lesson on sorting. Read the following article I found by using Google:http://www.daniweb.com/forums/thread6713.html

siddhant3s 1,429 Practically a Posting Shark

Sorry, I won't help,
This is a C code and I am too sure you have not written this yourself(even if you have, I have no respect because it is not in the language supported by this forum i.e. c++. I don't even have respect if you are a C guru.) .
http://www.daniweb.com/forums/announcement8-2.html

Follow what I told you to get a neat help. Also, if you are not well versed even in the basic of c++, you should perhaps follow Clockowl's suggestion and read the tutorial.

I don't think you are following a textbook of c++ because if you were, this problem would not have there.

So it is better to shed some hand on actually typing the code your self (in C++) rather than posting others code.

siddhant3s 1,429 Practically a Posting Shark

>>i just wanted to know the basics of what to do in this problem.
RTFM.
To be polite, here is are the steps you must take:

1. Construct an Array
2. Ask user how much quantity of data is to be inputed
3. Input all those elements from the user
4. Find the Min and the Max and display them
5. Find the Arithmetic Mean(average what you call) and display it.

Now, the above step may sound too trivial. But I want you to code at least the first two step and post them here.
If you show us your efforts, we will definitely show our help.
Also note, that there are several search engines(Google being most notable) free of cost provided to you. Please use them.
Here is a link I found in just 10 second of Googling, which might be helpful to you in step 3 :
http://www.fredosaurus.com/notes-cpp/arrayptr/array-examples.html