mrnutty 761 Senior Poster

Since you are already using std::string, I figure to help you concise this function :

//method to check if the current character is a vowel
bool IsVowel(char chr)
{
	 switch (chr)
    {
    case 'A': 
    case 'E': 
    case 'I': 
    case 'O': 
    case 'U': 
    case 'Y':
    case 'a': 
    case 'e': 
    case 'i': 
    case 'o': 
    case 'u': 
    case 'y': 
 
        return true;
    default: 
        return false;
    }
}

into this :

bool isVowel(char letter){
 string vowels = "AEIOUYaeiouy";
 return vowels.find(letter) != string::npos;
}
mrnutty 761 Senior Poster

Don't let this blow your mind:

aReturnType some_function_name(aParameterType some_parameter, aReferencedType& some_ref_parameter) {
  aType some_variable(SOME_INITIAL_VALUE);
  for(anIterator some_iterator = some_start_value;some_iterator != some_end_value; ++some_iterator)
    some_variable += some_other_function_name(some_parameter, some_ref_parameter);
  return yet_another_function(some_variable);
};

These are just phony names people use in text books to make examples (so is Foo and Bar, before you ask).

Or some funny typedefs lol.

mrnutty 761 Senior Poster

can't to work with this, because user input is string type name (:

string stringName = "goshy";
char charName = "goshy";

cout << stringName[0] << " " << stringName[1] << endl;
cout << charName[0] << " " << charName[1] << endl;

strings are made to replicate char arrays but be better

kings_mitra commented: Are you sure this is a C syntax !!! +0
mrnutty 761 Senior Poster

Its undefined behavior because of there is no Sequence_point.

mrnutty 761 Senior Poster

some hints :

char  ch1 = 'a';
char ch2 = '#';
cout << isalpha( ch1 ) << endl; //true
cout << isalpha( ch2 ) << endl; //false
mrnutty 761 Senior Poster

Thanks for the suggestion to change the file in notepad. I understand how that would work. Unfortunately, I am working on this as part of an assignment for a class and have to deal with the file as is.

Try something like this then :

string data = "01/01/2010,37.58";
	string::size_type pos = data.find_first_of(',');
	string date = data.substr(0,pos); //contains "01/01/2010"
	string strPrice = data.substr(pos + 1); // contains "37.58"
	float price = atof( strPrice.c_str() ); //contains 37.58
mrnutty 761 Senior Poster

Work backwards :

Data m1p1;
Data m1p2;
Data m1p3;

Data m2p1;
Data m2p2;

Data* pointerToM1P1 = &m1p1;
Data* pointerToM1P2 = &m1p2;
Data* pointerToM1P3 = &m1p3;

Data* pointerToM2P1 = &m2p1;
Data* pointerToM2P2 = &m2p2;

Data** pointer_to_a_pointer_that_points_at_m1p1 = &pointerToM1P1;
Data** pointer_to_a_pointer_that_points_at_m1p2 = &pointerToM1P2;
Data** pointer_to_a_pointer_that_points_at_m1p3 = &pointerToM1P3;

Data** pointer_to_a_pointer_that_points_at_m2p1 = &pointerToM2P1;
Data** pointer_to_a_pointer_that_points_at_m2p2 = &pointerToM2P2;

Data*** pointer_to_a_pointer_that_points_at_a_pointer_that_points_at_m1p1 = &pointer_to_a_pointer_that_points_at_m1p1 

//...and so on

But may I suggest you don't do this. If you tells us your actual problem, then we would probably be able to help.

mrnutty 761 Senior Poster

1) Easiest way, copy ALL of the data into notepad
2) On the notepad, click Edit->replace. Now replace all ',' with ' '
3) Now you can read in the date as a string, and the price as a double

mrnutty 761 Senior Poster

@OP: There is simply no reason to do this. Why would you want to do this?

mrnutty 761 Senior Poster

Here is what people usually do when creating a bullet class. Because bullets get
created and destroyed so fast, and because there are so many of them or can be. You
are better of using some raw arrays instead. Put a maximum cap on the number of bullets created. For example you can do something like this :

struct Bullet{
  vector3f startPosition;
  vector3f velocity;
};

template<int SIZE>
class BulletArray {
 private:
  boost::array<Bullet,SIZE> bulletList;
  int currentSize;
 public:
 BulletArray(): currentSize(){}
 bool addBullet(const Bullet& b){ 
    if(isBulletFull()) return false;
    bulletList[currentSize++] = b;
    return true;
 }
 //...more methods
};
mrnutty 761 Senior Poster

Do you know how to use polymorphism? Virtual inheritance? Pure virtual functions?
Problem with inline virtual functions? Try projecteuler.net. They have challenging
math problems for practice. Also research design patterns. There are plenty of stuff to
learn. Here read this. That should keep you busy.
Also how learning to implement different data structures? List, trees, TRIE ...

mrnutty 761 Senior Poster

Yes it is a problem. Each time you include that .h file, it will define a new static variable.

mrnutty 761 Senior Poster

Try this :

cop3530::hash_table<int,cop3530::linear_probe> ht(10);
mrnutty 761 Senior Poster

Yes. But here is another option.

In you Node class, you can use typedef like so :

class Node{
 typedef int DataType;
 //...blah blah blah
}

Now in your list and iterator class, instead of using int as a parameter, use Node::DataType. So :

Node(Node::DataType t);
private:
 Node::DataType data;

Thus by using Node:: DataType, you have less work to do, if you want to change say
from int to string again. Then All you would have to do is change typedef int DataType to typedef string DataType

But the short answer to your question. Yes.

mrnutty 761 Senior Poster

>>Does it tell you what I know about C++?

Not really. Although you *solved the problem fast, it could be better. How far of C++
do you know? Any knowledge about meta-programming? Usually, the best way to get better at programming is to design project. That way you get a chance to practice algorithms and design patterns. But if you just want some problems to solve, then
google online. There are a lot of sites dedicated to practice problems.

-----
*solved: haven't really tested the program, just taking your word.

mrnutty 761 Senior Poster

Short answer : Replace all string data type with int

mrnutty 761 Senior Poster

Use cop3530::linear_probe

mrnutty 761 Senior Poster

No, use header files to define the skeleton of a class. And if possible, use .cpp
file to define those classes. One of the main reason why one would do this is for
organizations reasons. In some cases, having the definition in the .h file can lead
to multiple definition errors in C++. Another reason is because it makes your code cleaner. And also, when you make a slight change to the header file, you will have to
compile every file that uses the header file, while if you had a .cpp, then you would
only need to compile the .cpp.

mrnutty 761 Senior Poster

Cut off the upper end of the range to account for the addition.

rand() % (20-8) + 8

That code does not go up to 20. It goes up to 8-19. This code produces in range of 8-20.

int random = rand() % 13  + 8;
mrnutty 761 Senior Poster

I commented on your actual code. I comment it as I read it.

//Good, gaurds are good, but name them something useful like
// MATRIX_H_
#ifndef GUARD_MM_info
#define GUARD_MM_info

#include "stdafx.h"
#include <vector>
#include <string>
#include <iostream>
#include <utility>
#include <algorithm>

class Matrix {
public:
	//I like this typedef, although I would call it MatrixType.
	typedef std::vector<std::vector<int> > matrix;
	
	//there is really not point to make it const char, just use char
	//also what does calculate do? I cannot tell without looking at its implementation
	//so thats a bad sign already
	int calculate(const char);
	//forget about using reference in primitive types, they make no difference
	//plus a class should have minimal public methods it needs, so to make its job less
	//Thus you should'nt have print and read function in this class, it does not belong there
	void print(const char&);
	void read();
private:
	//Although Its private, at least give it better names so I can understand its job
	void Menu1(); void Menu2();
	void Menu3(); void Menu4();
	void Menu5(); void Menu6();
	//again const ref on primitive types is no point
	int space(const int&);
	void readLeft();
	void readRight();
	//add and subtract probably has very similar code, therefore you can abstract the problem
	//thus less code and easier time for you. 
	void multiply();
	void add();
	void substract();
	std::pair<int, int> setSize(std::string);
	void setValues(const char&, matrix&, const std::pair<int, int>);
	matrix ML;
	matrix MR;
	matrix R;
	int spaces, spaceout;
};
void Matrix::multiply() {
	std::vector<int> v(MR[0].size(), 0);
	R = std::vector<std::vector<int> >(ML.size(), v);

	for(int i = 0; …
mrnutty 761 Senior Poster

>>First_person

Excuse me, I use mixedCaseForMyName, as in firstPerson :)

StuXYZ commented: lol, more code reviews for me. +3
mrnutty 761 Senior Poster

First take srand( time(0) ) out of the constructor. Put srand( time(0) ) at the beginning at main.

Second do this :

strength =  (rand() % 20) + 8;
dexterity = (rand() % 20) + 8;

So that way they both get different values range from 8 to 27.

mrnutty 761 Senior Poster

First tell me what do you know about C++? And check out my sig.

mrnutty 761 Senior Poster
mrnutty 761 Senior Poster

>>Oh wow, I didn't even think to break the isupper, islower, isdigit into seperate functions. I'll try it. Thanks

No problem. The more function you create and thus divide the program, the better.
That is because of re-usability. So in later on the code, if you want to use the
hasUpperCase function then you can just call it, instead of copying and pasting code.

Using functions makes your code more readable and cleaner and better maintainable, so
the more the merrier.

mrnutty 761 Senior Poster

>>the best way to promote C++0x is to use it and teach it, yes

Lol, yes. But lets leave that to the C++0x forum.

mrnutty 761 Senior Poster

I can implement it for you for $100.00 US dollars.

mrnutty 761 Senior Poster

Oh so you mean in 1 location, there can be up to 3 treasures. Can you show me how
are are setting up your 2d array. The size and whatnot.

mrnutty 761 Senior Poster

>>This function works for a whole string test

Sure, the only problem is that most compiler right now do not support the auto keyword,
unless you got the very recent ones, which I doubt OP has. Although I might be wrong.

mrnutty 761 Senior Poster

Also note that im new to all this so if you say like "IDE" and stuff like that plz tell me what it means XD.

Most of the time, when someone throws around a lingo, you can just google it and find out.
IDE stands for Integrated_development_environment. You use it, to compile codes and to develop and make projects. You
will need that in order to run your code.

mrnutty 761 Senior Poster

>>Or even better:

I beg to differ. Not only is that hard to read, but also harder to understand, plus
it leave the user to remember to delete the object returned.

@OP: I advise you to use string, but if this is for learning purposes, then you
can do something like this :

void substr(const char *src, char *dst, int start, int len){
	/* Do error check here */
	int i = 0;
	while( start != len){
		dst[i++] = src[start++];
	}	
}
mrnutty 761 Senior Poster

When you compare your answer, make sure its in correct units, radians or degrees?

>>so my first question, when i use the first fourmla, then how can i use the second one?


The first and second formula has nothing to do in this case. The first formula
shows one definition on cos and sin, while the second shows another definition of
cos and sin. The second definition is a recursive definition.

mrnutty 761 Senior Poster

So what you should do is, make more function, specifically these :

bool hasUpperCase(const char * str); //returns true if str has at least 1 upper case 
bool hasLowerCase(const char * str); //returns true if str has at least 1 lowercase 
bool hasDigit(const char * str);//returns true if str has at least 1 digit
bool isInvalidLength(int len); //returns true if len is invalid length

and call those functions inside your verifyPass function like so :

bool verifyPass(const char *str){
 int len = strlen(str);
 return hasUpperCase(str) && hasLowerCase(str) && !isInvalidLength(len);
}

Now your job is to code the hasUpperCase, hasLowerCase and isInvalidLength function.

mrnutty 761 Senior Poster

I will be glad to help, first to start out. Here are some guidlines.

1) Get a IDE, I suggest one of these, codeblocks or visual studio 2008.

2) Now you need to start making projects, so google online on how to make projects with either codeblocks or visual studion, whichever you choose to download.

3) Now here is a tutorial in C++. Thats a good start at least. Try some code out. Get it to work and start learning.


We're here to help, so if you have any problems, just ask.

Qu4n7um commented: 100% EPIC ANSWER !! +0
mrnutty 761 Senior Poster

The maximum value a int can hold in java is 2,147,483,647 while
13! = 6,227,020,800.

So you see that an int cannot hold 13! or higher. Its only big enough to hold 12! or less.

mrnutty 761 Senior Poster

Your syntax is wrong. You need to use the scope resolution operator.
So your call would look like this myEngine::GeneralCore::WindowManager:: DisplayWindow()

mrnutty 761 Senior Poster

There are a couple of options.

1) Use std::vector< std::vector >
2) Use dynamic arrays
3) Create a static array, with big enough size, and get the limited user's input as size. And use that variable, as the max size.

mrnutty 761 Senior Poster

Example:

class list{
public:
  class Node{
  };
};

list::Node n; //declare a Node object
mrnutty 761 Senior Poster

Hey guys, you are getting way off topic. You guys made this thread your own.
Plus, in this debate, I would have to agree with mike_2000_17. There is no, if hardly any performance difference between a reference versus non-reference when it comes to primitive types. If you disagree then do a performance check.

mrnutty 761 Senior Poster

Before anything, I need to see the graphCalculation code. Or at least how it treats
the x and y passed in.

mrnutty 761 Senior Poster

a better solution would be to define an operator>>. For example :

std::istream& operator>>(istream& is, Client& c){
 return is >> c.acccount >> firstName >> lastName >> balance;
}

//...in main somewhere
Client c;
while( file >> c) vectorVariable.push_back(c);
mrnutty 761 Senior Poster

You need to abstract when possible. So in the example you gave, create a prase
function and call it on each function.

template<typename ReturnType, typename InputType>
ReturnType void prase(const InputType& in){
 /* do praising here */
 /* and return whatever you need to return */
}
mrnutty 761 Senior Poster

Thats wrong, you declare gptr as int *gptr , so that means, it cannot point
to float(s). Which means that when you did gptr = new float[m_size]; it should
have given you a compiler error. Change the float to an int.

Also dont forget to delete the pointer in your destructor.

mrnutty 761 Senior Poster

>>This isn't a bad attempt

Yes it is. It wont even compile

@OP: as I hinted earlier, use the size parameter in the Student constructor as
an argument to the new operator. IE, your second constructor is almost the same
as the first, but instead of 3, you use the size variable thats in the constructor parameter.

mrnutty 761 Senior Poster

Then that means you need to abstract the problem. Create 1 common function, that
does a common functionality that each of the other function does, and inside the other function, call that common function.

mrnutty 761 Senior Poster

Why do you need centimeter and meter, you can just work with meter. Centi is just an
extension of meter? And come to think of it, your just scaling the width and the height. It makes no sense to me, to put that in the constructor. It should go as a
member function. This class is essentially the same as yours :

class Rectangle{
private:
	unsigned width;
	unsigned height;
public:
	Rectangle(unsigned w, unsigned h)
		: width(w), height(h) {}
	
	void scaleWidth(float s){
		width = (unsigned)ceil( width * s);
	}
	void scaleHeight(float s){
		height = (unsigned) ceil( width * s);
	}
	void scale(float s){
		scaleWidth(s); 
		scaleHeight(s);
	}
};
mrnutty 761 Senior Poster

First this constructor :

Student::Student(){
    int *gptr; 
    gptr = new int grade[3];
}

is incorrect, it has a memory leak. You already have declared a gptr in your .h
file, so you can just delete int *gptr thats inside the default constructor.

Second I don't see the definition of Student(int size); in your program.
So give that a try. Hint, use the parameter size, and the argument for the new operator

mrnutty 761 Senior Poster

>>what would best way to approach this in order to combine these 3 functions into 1?

The best way to do this is to not do it. Functions are there to help create more readability for the coder and the reader. The more the better. By trying to combine
functions into 1, you are sacrificing readability and usefulness for a little performance if any. Why do you even want to do this. Maybe if you tell us more about
your program, then we can help make it faster. I'm sure you have other bottlenecks.
Plus I doubt it will give any performance boost. It might save a few calls, and stop
some level of indirection, but thats nothing in this era of computing.

mrnutty 761 Senior Poster

Have you converted the x and y variable into world coordinates? Does graphCalculation
takes the mouse coordinate in world space? Or does it want to raw pixel points?
Can you show how the graphCalculation function looks like? Can't really help
without more info.

mrnutty 761 Senior Poster

>>how would one define RANDOM FILES

string randomFile = "randomFile.txt"

>> well as suggest ways of creating

ofstream newFile(randomFile.c_str());

>>updating them in Visual C++
"Updating" is subjective, what kind of update?

If you want better answer, We need better and more specific questions.