mrnutty 761 Senior Poster

LOL firstPerson you're at it again.

Stop and engage your grey matter before your EGO flares up and takes over.

I never said using a map was invalid...

Yes YOU would, and YOU would probably be right. But this isn't about you.

Look at the OP's code. Look at his number of posts. Do you think he is advanced to understand your code. This is something a whizz kid would come up with after using c++ for a long time. All your code does is present itself as a cerebral mind numbing exercise for the OP. What do you think his professor is getting the student to achieve here? This task can be achieved simply using just arrays and procedural logic. A student must learn to walk before he can run. Comprende?

Hahaha, I don't speak spanish. Anyways, he did not mention anything about this being a h.w assigned by his professor. For all I know he might be doing this for practice, thus suggesting something better. And I don't think my code was hard to understand, in fact there shouldn't be any troubling understanding it unless one never seen std::map before.

>>I never said using a map was invalid...
Well...."Why should he use a std::map for this?". From that I got, "he shouldn't use map", which is a little variation of "using map here is bad". Maybe just misinterpretation.


Anyways, my code was just a suggestion. OP does not have to follow it. Thats …

mrnutty 761 Senior Poster

Huh? Map is meant to map one data to another. Thus mapping a character to its frequency is perfectly valid and better than using arrays. Its more flexible, safe,robust, and depending on situation would use less memory. I said the code is a little better, because it can be improved but is still better than using raw arrays.

>>Sure a std::map would work but the beauty comes from achieving the same thing with much more rudimentary tools... like classes and arrays

I beg to differ. I would rather use the right tool for the job then try to hack up things using the basic stuff.

mrnutty 761 Senior Poster

If you can you should really use something like std::map for this. For example, doing something like this is a little better:

#include <map>
#include <iostream>
#include <cctype>
#include <fstream>


using namespace std;

class AsciiCharacterCount{
public:
	typedef std::map<char,long>::const_iterator constIterator;	
private:		
	std::map<char,long> asciiFreq;	
public:
	void update(char ch){	 
	 if(isalpha(ch)) asciiFreq[ch]++;
	}
	void update(const std::string& str){
		for(int i = 0; i != str.size(); ++i) update(str[i]);
	}
	long frequency(char ch)const{ 
		 constIterator itr = asciiFreq.find(ch);
		if(itr != asciiFreq.end()) return itr->second;
		else return 0;
	}
	constIterator begin()const{ return asciiFreq.begin(); }
	constIterator end()const{ return asciiFreq.end(); }	
};

int main(){
 AsciiCharacterCount freqCounter;
 freqCounter.update("Alalyze each of these letters");

 AsciiCharacterCount::constIterator itr = freqCounter.begin();
 while(itr != freqCounter.end()){
	 cout << "'" << itr->first << "'" << " frequency = " << itr->second << endl;
	 ++itr;
 }
 return 0;
}
mrnutty 761 Senior Poster

Also whats with pointers? Be smarter about your code and use reference or smart pointers if you have to.

mrnutty 761 Senior Poster

The second one would probably use less memory. And normally you would use the second one unless you have a compelling reason to use the first.

mrnutty 761 Senior Poster

Your code to delete linked list should look like this :

linkedList::~linkedList{
 Node* current = head;
 while(current != NULL){
   move(current,1); //move current to next node
   destroy(head); //delete head 
   head = current;
 }
}
mrnutty 761 Senior Poster

1) Forget the pointer crap, don't use it unless you really have to. Or if this is for practice then its ok for now.

A easy way to do it is like so :

template<typename T>
T getInput(const string& msg){
 cout << msg ;
 T var = T();
 //check if input failed
 while( !(cin >> var) ){
    cin.clear(); //reset the stream
    cin.ignore(256,'\n'); //read and discard the bad input
   //now try to read again
    cout << "\nBad input try again : "; 
 }
 return var;
}

int main(){
 int i = getInput<int>("Enter a number : ");
 float f = getInput<float>("Enter a number : ");
 char ch = getInput<char>("Enter a letter : ");
 string s = getInput<string>("Enter your name : ");
}
mrnutty 761 Senior Poster

Here is something to get you started :

int main(){
 const int MAX_WORD_ALLOWED= 1000; //1000 words allowed
 const int MAX_WORD_LENGTH = 256; //words length cannot exceed this amount

 char listOfWords[MAX_WORD_ALLOWED][MAX_WORD_LENGTH] = {};

 ifstream fileInput("test.txt");
 unsigned wordNumber = 0;
 
 while(fileInput.get(listOfWords[wordNumber++],MAX_WORD_LENGTH) && wordNumber < MAX_WORD_ALLOWED ){
   //blah blah blah
 }
}

Its not tested, but you should get the idea.

mrnutty 761 Senior Poster

^^ Well done firstPerson. My opinion of you has just sky-rocketed.

Just be careful not to fall into the trap of being her new gay best friend who she moans about all her new boyfriends to. Keep the sexual tension high if you want anything else to happen with her.

And don't fall back into the role of being HER little emotional puppy dog. Run your life how YOU see fit. You are the man. Again if you need any advice, feel free to PM me.

Not to be rude or something, unless I know the person, I really don't care how a person feels about me, although I try to be friendly.

And I spent the night with her last night. I began thinking of how I don't have the feelings for that I though I had. Not to sound like an asshole but its the truth, I really don't care much for her, since I know I could get her. Maybe I needed that confirmation that I could get her back if I wanted. I know that sounds like an asshole but its the truth. But IDK, I'll see what happens. Thanks for everything btw.

mrnutty 761 Senior Poster

>>The chapter I am reading only touches on structs, so I need to research that topic more deeply

Let me clarify that for you. If you know classes then you know structs. classes are no
different than struct except for their default modifier. For example :

struct F{
 int x;
};
class G{
 int x;
};
//...
F f;
G g;

f.x = 10; //valid, x is public by default
g.x = 10; //error, x is private by default
mrnutty 761 Senior Poster

Make your code easier by declaring the function as a boolean function instead of having a found flag. Thus after that change it becomes seemingly simple :

bool MyBS::search(const Node* root, int key){
   if root is null return false;
   else if key < root.key
           search(root.leftChild,key);
   else if key > root.key
           search(root.rightChild,key);
   else return true; //root.key == key   
}
mrnutty 761 Senior Poster

First this code :

class TitleExcept: public exception    // Class for handling errors about the book's title.
{
virtual const char* what() const throw()
{
return "Please enter the book's title using only letters.\n";
}
} errortitle;

there are a few problems with it. The function what() should be public. Also, there is no need for the virtual unless you think someone would inherit from TitleExcept. And I think TitleExcept is a bad name. Its name is not descriptive enough. Perhaps something like InvalidTitleException or BadTitleFormatException would be better. One las thing about this code. There is no need for errortitle right now. Let the user use statements like : throw BadTitleFormatException rather than errortitle. As a general rule, try to scope everything tight as possible.

holding vectors of book characteristics; ISBN, title, author, copyright date, and an indicator of whether a book is checked

I think that means this :

struct BookCharacteristic{
 string Isbn;
 string title;
 string author;
 //...and so on
};

class Book{
 std::vector<BookCharacteristic> info;
 //...
};

instead of a vector of each characteristic. That way its easier to maintain, change,
and use, not to mention less error prone.

As for the rest of your code, I'll let someone else inspect that. I'm getting tired.

mrnutty 761 Senior Poster

This should help

if(num < 0){ /* the number is negative */ doStuffWithNegativeNumbers(); }
else{ /*The number is not negative */ doStuffWithNonNegativeNumbers(); }
mrnutty 761 Senior Poster

Ok just an update if anyone cares or cared. So I am talking to her again. I told her how I felt. She told me how she felt. Now were not officially not going out again because I am in control and I decided when or if that happens. But right now
all I am doing is having dinner and talking to her a little and see if I really want to be with her. So thanks again to everyone for everything. God Bless.

mrnutty 761 Senior Poster

The size of myList is found by using the sizeof() operator. It should be a multiple of 4 bytes.

mrnutty 761 Senior Poster
struct Info{
 string name;
 int age;
 Info(const string& name = "", int age = 0)
  : name(name), age(age){}
};
void add(node* & x, const Info& information)
{
    if( x== NULL ) 
    {
       
        x= new node(information);    
    }
    else if( information> x->data )     {
        add( x->right, information);     
    }
    else  
    {
        add( x->left, information);      
    }
}

//...
//...
myList.add( new Info("james",23) );
myList.add( new Info("charles",32 ) );
mrnutty 761 Senior Poster

>>5A72 + 4573 = 9FE5

In an algorithmic way, you can do something like this :

string hex1 = "5A72";
string hex2 = "4573"
string res;
assert(hex1.size() == hex2.size());
bool hasCarry = false;
for(size_t n = 0; n < hex1.size(); ++n){
 string hexValues = "0123456789ABCDEF";
 char addedValue = (hex1[n] + hex2[n]);
 if(hasCarry){
   ++addedValue;
   hasCarry = false;
 }
 if(addedValue > 16) { 
    hasCarry = true;
    addedValue %= 16; //map 0-15
 }
 res.push_back(  hexValues[ addedValue ] )
}

The basic idea is to use simple addition algorithm like you would do on paper.
THe above code is not compiled so no guarantee. But it should give you and idea.

But an easy way would be something like so :

int hex1 = 0x5A72;
int hex2 = 0x4573;
int res = hex1 + hex2;
std::cout << std::hex << res << endl;
mrnutty 761 Senior Poster

They are just typedefs probably.

typedef int INT;
typedef float FLOAT;

so INT and int are the same and FLOAT and float are the same. Its just a different way to tell the compiler the data type.

mrnutty 761 Senior Poster

Why are you using pointers?

mrnutty 761 Senior Poster

Ok then maybe scott meyers can convince you on why to prefer non-member function rather than member functions.

mrnutty 761 Senior Poster

To load it when the windows start, you can port the .exe into the directory where the startup programs are located. That way, whenever you start your computer, your program gets executed in the background, just like other startup programs.

As for the rest of your question, you need to be very specific. Define all events and
what they are. What can the program do? What can't it do? How does it look? You should really have a concrete idea before you program this, as this will be a big project( subjective ).

mrnutty 761 Senior Poster

>> I found std::string didn't support some of the features I'd like it to.
Then inherit and add those features.

>>Why? You have provided no evidence for any of the suggestions you've given. You've said that I shouldn't use a static class function because it is more easily maintained, but you've given absolutely no examples to back that statement up.

Its hard to come up with a concrete example, but generally speaking it is easier to
maintain and change code that has loose coupling. Meaning that, it is easier to add
new features to a program that does not depend heavily on other things. As an example, consider this trivial problem: Design a program where a button controls a lightbulb, turning it on and off every other time the button is pushed. So its basically a lamp. A simple design for this might be like so :

class Lamp{
 Button button;
 LightBulb lightBulb;
public:
 //button turns on/off every push
 void off(){ button.pushdown();}
 void on(){ button.pushdown();}
 //...
};

This seems like an OK design, but notice that its highly coupled. Does every lamp
have to have a button to turn lightbulb on and off? Can we use some string to pull,
instead of the button, how about some type of voice recognition to turn light bulb on/off? So you see, using this design we would have to create many separate Lamp classes and whatnot. But if our design were better, meaning that lamp …

mrnutty 761 Senior Poster

Hints :

1) Use a forloop to sum values?
2) Use explicit formula to calculate sum of even integers?
3) Use standard library instead of writing forloops?

mrnutty 761 Senior Poster

>> Can C++ do graphics?
Yes

>> Can C++ do networking?
Yes

>>Does C++ contain every data structure that one would need?
Yes, and if it doesn't the programmer can create his/her own

>>Is C++ easy to learn?
Subjective. Depends on who is learning it. Some yes, and others no.

>>Are there defects in C++?
Subjective. Depends on what you call a defect. IMO no.

>> its hardly the best tool to use in most applications.
I would agree that c++ is not the best tool in all applications. There are things that are easier to accomplish in other languages, but c and c++ can do it all.

Maybe you are thinking C++ with external libraries can do graphics and networking, but not pure C++. A programming language is a tool. A good tool should provide the necessities for a programmer to solve the problem. Instead of giving you a wood, nail, and a hammer like C++, a good programming should already have generic stuff built in for you, so you avoid all the scrapes and cuts. C++ is definitely not the easiest language to learn, and when I say learn, I don't mean the basics, I mean the whole enchilada. I

mrnutty 761 Senior Poster

>>Why should a string class have a function to generate a random string of a certain base." I'm going to go with because the function has to do with strings. And not just strings in general, it uses my string class. By putting that function there it makes it clearer that the function is meant for handling my string class, not std::string or C strings. By having it a global function, it loses that association. For that matter, if I saw genRandomRadix() I wouldn't immediately think it had anything to do with strings, let alone my string class.

Then why create your own string class? Just inherit from std::string if you need to.
That way, you can use polymorphism and generateRandomStringInBase(int base), could
work with either.

>>And bear in mind, this function is static. It could be used in the same ways as a global version of the function, but the association with my string class is made clear

If the function is static, then that should be a big clue that, that function needs
to be a standalone function. That it does not need to be coupled with your string class.

>>if I saw genRandomRadix() I wouldn't immediately think it had anything to do with strings, let alone my string class

Yea I admit it wasn't the best name. How about, generateRandomStringInRadix(int radix) ?

And BTW: using your way, you would always have to create a MyString class. …

mrnutty 761 Senior Poster

If possible, header should contain a skeleton for the desired Object.
For example a header might contain a class skeleton named Car, and you might define
the actual implementation of Car in a different .cpp file. Another example, you
might declare some functions in a header, but do the actual implementation in a different .cpp file.

//BestClassInUniverse.h
// this header defines the skeleton for the BestClassInUniverse
class BestClassInUniverse{
public:
  void doTheBestThingInUniverse(); //skeleton
};
//BestClassInUniverse.cpp
//actually defines the implementations
BestClassInUniverse::doTheBestThingInUniverse(){
  //some  top secret code.
}
mrnutty 761 Senior Poster

How do you know if its working correctly? It looks like a problem with improper initialization. How about you post more code so we can take a look.

mrnutty 761 Senior Poster

The difference comes in for later maintenance. If you want to add more radix to you would have to add more enums. And if you want to disable the use of a radix you need to remove enums, and other codes. The way I showed you might makes it easier to handle change. As always, you should design for change.

You are adding things to your string class that does not need to be in there. Why
should a string class have a function to generate a random string of a certain base.
That should be a regular function. Once again, a class should hold the minimal amount
of data that it needs.

A valid radix is usually from base 2-26, but you can design for almost any valid radix if you want. Its your decision.

The bottom point is, whether you see it or not. The first design is more flexible because it does not have the string class heavily depend on other external things, than what it needs to depend on. Its easier to maintain and change.

As always, there are many ways to design a class to solve a problem. A good way to design such a class, is to think in the future, and see what can be abstracted.
So that the design becomes more flexible, robust, and reusable.

mrnutty 761 Senior Poster

@firstPerson: The way it's set up right now, the enum can also denote things not related to integers of different radices, such as strings of all capital letters. And while I certainly could have a function for that kind of thing, it'd introduce new problems, such as what to do when an invalid base was passed. I guess just return an empty string?

@Narue: you bring up a very good point. I think I might go with that suggestion.

Your design seems to be very coupled. Using enums like that is not a good idea. That's
not what enums were made for. You would be better of doing something like this :

MyString genRandomRadix(int radix) throw InvalidRadixException(){
 //blah blah blah
}
MyString toUpperCase(const MyString& str){
  //more blah blha blah
}

That way you can use it like so :

MyString id = toUpperCase( genRandomRadix(BASE_16) ); //ex: 0xFFF12 instead of 0xff12
 //versus what you probably do :
 MyString id2;
  id2.genRadomRadix( MyString::HEX_BASE ).toUpperCase();

The first one is much clearer and more usable in my opinion.

mrnutty 761 Senior Poster

@OP: Are you allowed to do this :

struct StudentInfo{
  string name;
  int id;
  //more stuff if you need it

};
struct StudentNode{
 StudentInfo data;
 StudentNode *next;
 StudentNode() : data(), next(NULL){}
 StudentNode( const StudentInfo& info, StudentNode *pNext = NULL)
  : data(info), next( pNext){}
};

class StudentList{
 //...details
public:
 void add(const StudentInfo& info){
    if(start == NULL){
      start= new StudentNode(info,NULL);
    }
    else {
        StudentNode *lastNode = moveToLastNode(start); //returns a Node to the last member
        lastNode->next = StudentNode(info,NULL);
    }
  }
}
mrnutty 761 Senior Poster

Why don't you seperate the randomString(HexOrDecOrOctal) function from the class, and
make it a regular function. Like so,

MyString genRandomString(int radix){
  validate(radix);
 //...
}

No need for enums or IDs, just pass in the base, and the function returns something
that has to do with that base.

mrnutty 761 Senior Poster

In my college, instead of using C++ as an introductory language, the college changed it to matlab because its better suited for engineers, and easier, and more useful for engineers that are not in CSE branch.

mrnutty 761 Senior Poster

Its probably because the professor wants the student to learn, instead of blindly using
a function.

Fbody commented: Absolutely! :D +2
mrnutty 761 Senior Poster

>So knowing that, what do you think I should say?

Do you even need to ask? If you want to be with her or just want to be her friend what you need do is EXACTLY the SAME... Yes, that's right. It's exactly the same.

You act and speak to her like nothing happened.

You: Woooohooo looky here, well if it isn't my little side-kick from last summer. How's things?

Her: Hey firstPerson, haha. Yeah I'm good blah blah blah.


If she starts mentioning other guys, you cut her off and say you gotta run.

Like I've always been saying. Act indifferently, do whatever you want to do.

Alright, I am going to try to take your advice. Realize that its not that easy to just forget and act like
nothing happened. She cheated on me. I'm not sure if you ever got cheated on by a girl that you cared for, but
it does not feel good. And I realize that it was her hormones that made her do that, but I'm sure she still has some knowledge
about what she was doing. Anyways, I'm not sure what I'm going to say. But later on, i'm going to message her. And ask her if we
can talk. If everything goes well then good, if not then whatever. I'll let you know what happened tomorrow.

iamthwee commented: Godspeed +0
mrnutty 761 Senior Poster

Wow really? I though it was a good conversation to go with.

Anyways, I do not want to get back with her. I do not want to see where it leads me to.
I am done with her. I think I would rather just be friends. So knowing that, what do you think I should say? BTW: This will be in a college environment.

mrnutty 761 Senior Poster

Divide and conquer. In this case, if you break it up into function you will see that
the logic is easy to see.

#include <iostream>
using namespace std;

void printN(const char c, int N){
 while(N--) cout << c;
}
void printSeq(int start, int end){
  while(start != end){ cout << start++; }
}
int main(){
 const int MaxHeight = 5;

 for(int i = 1; i <= MaxHeight; ++i){
    if(i % 2 == 1) printN('*',i);
    else printSeq(0,i);
    cout << endl;
  }
 for(int j = MaxHeight; j; --j){
    if(j % 2 == 0) printN('*',j);
    else printSeq(0,j);
    cout << endl;

 }

  return 0;
}
mrnutty 761 Senior Poster

I think it maybe due to floating point conversion. Does cap necessarily need to be a double?

mrnutty 761 Senior Poster

'Is C++ the King of all Languages, it will always be around and is the best programming language ever made.'
Well, that was a giveaway. I answered 'YES'.
Well I got it wrong.

Can C++ do graphics?
Can C++ do networking?
Does C++ contain every data structure that one would need?
Is C++ easy to learn?
Are there defects in C++?


I really do not see why you think C++ is a king of all language? It falls short in being
the king of all language. Hell if it was the king of all language, then there would be
no need for Java, C#, jaascript, html ...

I think the professor was giving the students some free points, in which you failed to
earn. Don't let your love of C++ hinder the actual facts. The fact is, although C++ is a very popular language, its hardly the best tool to use in most applications.

mrnutty 761 Senior Poster

>>LINK : fatal error LNK1561: entry point must be defined

Thats usually means that you haven't defined main. What type of project did you create?
What type of IDE?

mrnutty 761 Senior Poster

Can you post your question a little more clearly with some context?

mrnutty 761 Senior Poster

LMFAO FirstPerson, you're at it again. STOP this sh*t right now. The reason why this girl dropped you is because of what you're doing right HERE right NOW. Quit with this, 'but she's sooo much more smarter than me, she does this she does that... I'll pretend to ask for her help with homework then try worming my way back in. blah blah blah.'

You're putting this girl on a pedestal. She doesn't want to be here. It does NOTHING for her. All she ever wanted is for you to stop running around with your dick tucked in-between your legs and LEAD her. SHE wants to be the one running up to you and asking for help with her homework. You asking her for help and dumping the male role on her simply confuses the sh*t out of her. In fact I'm placing 2-1 odds that during your summer break, she fantasized about you turning up on her doorstep and tearing off her clothes. But you didn't. Instead you moped around and thought about how much she broke your itty bitty heart.


Holy Mary mother of God. Nooooo. You thinking is what is causing the problems here.


I majored in history, but you are right, there is no point in avoiding her. Speak to her ... the sooner the better.

Look. If you was me. This is what I would do:

Me: Hey _______, how are you. Long time no speak?
Her: Hey iamthwee . …

mrnutty 761 Senior Poster

Oh sorry, this is what I meant.

while(std::cin){
  if(std::cin){
     getnames();
    if(std::cin){ 
       getgrades(); 
     }
  }
}
mrnutty 761 Senior Poster

Do something like this :

while(std::cin){
  if(std::cin){
    getName();
    getGrades();
  }
  
}
mrnutty 761 Senior Poster

In your first post you can do this :

void print(const char*p){
 cout << p << endl;
}

and call it like so :

int main(){
 print("hello");
 print("hello");

}

Try that first

mrnutty 761 Senior Poster

Realize that from your code, students and grades might not be the same size. You should instead do something like this:

for each students in the vector students:{
  get student grades.
}
mrnutty 761 Senior Poster

OK, she's not a skank. Metaphors? Call a spade a shovel mate. Anyway, grab another one, there are plenty out there. Another notch on the old bed post. We'll make a philanderer out of you yet! God hates drinkers but absolutely loves fornicators.

Yea you are totally right. Maybe I should just focus on school and hang out with my close friends that wont peer pressure me, and forget about chasing girls for a little, although it might be fair game if they come to me. What do you suggest?

mrnutty 761 Senior Poster

>>I can see you're not in the mindset to get with this girl again. You could, but clearly you're not there.

Thank you.


>>The only thing that I disagree with is you totally ignoring her. This is still your EGO controlling you. Talk to her. You're not pawning after, you're simply showing her she has NO affect over your state. It can be as simple as a, 'Hey how are you?'

Oh man, you hit the nail in the head. I was contemplating whether to talk to her or not. Because she is in most of my classes, and she is mega smart(4.0GPA in CSE), I will definitely need help with the upper classes that I am taking. Do you think, I should try
to make amends, and start out by asking her help in a homework or something. And then try to be friends again? What if I want to get back with her after I talked to her. What if she wants to get back? I need to think about this a little.

>>This is important because the whole of the higher education system is based upon social networking. You know her ... she knows you ... she knows a few of your friends etc. It is almost impossible to cut one off entirely and have it NOT affect some other part of your life.

You must have a P.H.D in psychology and have majored in social science or …

mrnutty 761 Senior Poster

>>test.setValue(value);

test[0].setValue(value);

I'll let someone else criticize your code. Feel too lazy right now.

mrnutty 761 Senior Poster

>>At one point you say she looks damn cute and in another you say you are TRYING not to get back with her. If you didn't want to get back with her you wouldn't have to try would you?

Because I said she looked cute does not mean I want to get back with her. And I do not want to get back with her, even though I might feel like I want to. I know that sentence contradicts itself, but I hope you know what I mean.

>>It's OK to admit that she hurt you and you'd damn well love to hit that again

I hereby admit to daniweb and all its members, that she did hurt me, and it still hurts, and I damn well do want to hit that again. But believe me when I say, I am restraining myself. I know that if we go back out, I'm gonna have trust issues. And
its not that easy for me to be a player like person, because of how I grew up. Although, I probably could.

>>You know very well that the reason you don't want to talk to her is to protect your EGO. You also know that it is a very self destructive thing to do.

I agree. My ego is hurt.

>>You may not realise this now, but this girl could still be yours. Everything you have is at your disposal to make this girl yours again. …

mrnutty 761 Senior Poster

Whooaah. What THIS??

Did you get a case of the clap or what? Holy Cow, I wouldn't want to get back with her either, old skank. If you do, make sure you got a bottle of penicillin handy.

Lol, no. And actually, for some reason, I take offense that you call her that. And would appreciate it if you don't call her a skank.

The above quote was a metaphor. I was replying to iamthewee's metaphor, in a metaphorical manner.