mrnutty 761 Senior Poster

Also, your method definitions, e.g.,

void dayOfTheWeek::printDay()
{
	cout << "Today is: " << day[dayNum]  << endl << endl;
};

and onward should not end with a semicolon after the brace (you do still need the ones at the end of your class declaration and your const array).

That should not matter.

mrnutty 761 Senior Poster

Use vectors of string.

vector< string > customers; //size == 0
//do stuff

//menu stuff;
if(!customers.empty() )
   cout <<  "Display Members ? \n";
//other menu stuff

To add customers, you can use the push_back method of vectors;

vector< string > customers;
customers.push_back("Phil");
customers.push_back("Tyler");

Here is some reference

mrnutty 761 Senior Poster

Post your code, we have nothing to work with except your unclear
wording.

What do you want to do ?
What did you do ?
What were the errors ?

mrnutty 761 Senior Poster

Just use the stringstream to break a string into tokens :

stringstream tokenBreaker;
string aLine = "Please break this into six tokens";
tokenBreaker << aLine; //insert string
string tokens[7]; //for now lets not use vectors and do it manually
int currentToken = 0;
while( tokenBreaker >> tokens[currentToken]  && currentToken != 7) 
       ++currentToken;
mrnutty 761 Senior Poster

Yes ship them over in my direction.

mrnutty 761 Senior Poster

OMG, I am going to kill my self, I shall call Narue, Double N from now on, i.e Ninja Narue because you always beat me to the post.

mrnutty 761 Senior Poster

1) How about using vectors ?
2) How about using 1d array to represent 2d ?
3) In passing 2D arrays, you need to specify the number of columns before hand, like so :

const int COL = 5;
void init(int Array[][COL], const int ROW){
//TODO logic here
}
int main(){
  const int ROW = 5;
  int Array[ROW][COL];
  init(Array,ROW);

  return 0;
}
mrnutty 761 Senior Poster

>> Except there is one difference between lions and humans - intelligence

And , humans have thumbs, they can walk with 2 feet, they do not
have as much as body hair( usually ), humans teeth are a lot weaker,
we do not have as long and visible tail (usually), our babier aren't
as cute, and we aren't as friendly( usually).

Rashakil Fol commented: WOW THIS IS SUCH AN INTELLIGENT COMMENT +0
mrnutty 761 Senior Poster

Damn Narue, your a Ninja; Thats another post you beat me on.

mrnutty 761 Senior Poster

From what I see you are doing :

cout << "Quadratic equation\n";
    cout << "enter a: ";
    float a;
    cin >> a;
 
	cout << "Enter b: ";
    float b;
	cin >> b;
 
	cout << "Enter c: ";
    float c;
	cin >> c;
 
	if (isnum(a)&& isnum
		(b) && isnum(c) && a!=0) {
	float z = pow (b,2);
 
	float x = z - (4* a *c);

Do this instead :

string a , b, c;
	cout << "Enter a : ";
	cin >> a;
	cout << endl;
	cout << "Enter b : ";
	cin >> b;
	cout << endl;
	cout << "Enter c : ";
	cin >> c;
	cout << endl;
	
	if (isDigits(a.c_str())&& isDigits
		(b.c_str()) && isDigits(c.c_str()) && !a.empty()) {
		
	float z = pow (atof(b.data()),2.0);
  
	float x = z - (4.0* atof(a.data()) * atof(a.data()));

The main this there is the use of std::string which resides in the
string library, i.e #include<string> .

The other main thing is the use of atof, although not the best solution,
it is the simplest. It convert a char* to a number if possible.
For instance,

float distance = atof("24.001"); //distance will equal 24.001
mrnutty 761 Senior Poster

You are on the right track. Consider making the name of that function
better. Also you might want to make the base case more explicit like this :

void convertDecimalToRadix(int num, int base)
{
	if( num == 0 ) return; //base case
 	
	binequ(num/base, base);
	
	cout<< num % base; 
}
mrnutty 761 Senior Poster

This function can be more simple :

int isnum(const char *p) 
{
     if (*p) {
          char c;
          while ((c=*p++)) {
                if (!isdigit(c)) return 0;
          }
          return 1;
      }
      return 0;
}

Maybe to this ?

bool isDigits(const char * strNum){
 while(*strNum){
        if(isdigit(*strNum++) ) continue;
        else return false;
  }
 return true;
}

You use isnum function here :

if (isnum(a)&& isnum
		(b) && isnum(c) && a!=0)

but the variable a, b, and c are of type float? Perhaps consider
making it of type char *, then convert it to a number ?

mrnutty 761 Senior Poster

operator new returns a void*, in which it is converted implicitly to whatever
type you are using with assignment operator.

operator delete does not return anything.

mrnutty 761 Senior Poster

Obviously your add function is wrong. How about you ditch the sorting
part of this and make a regular linked list, unless you haven't done that
already?

And your print function is wrong :

void printall() {
			for(node* x = bottom; x != NULL;) { 
				std::cout <<x->data<<"\n"; x = x->next; 
			} 
		}
mrnutty 761 Senior Poster

Google blender. Its a good 3d modeler. You can create some 3d model and
use C++ to load it in, and display it with some API like openGL or direct3D.

mrnutty 761 Senior Poster

Basically it shifts bits.

Take for example, the number 4. In binary, its 0100. Each digit in the binary for is called bits. 8 bits = 1 byte.

If we use the bitshift operator like this

int shiftVal = 1;
int value = (4 << shiftVal);

we shift the bits to the right, shiftVal amount of times. Since shiftVal
is 1, we shift all the bits 1 position to the right, so :

//before shift
4 = 0100
//after shifting 1 bit
val = 1000;

lets take another example, consider the number 1. It binary for is
0001. If we do this , (1 << 4). That means we shift all the bits
in the number 1, 4 times to the left. So

//before the shift
1 = 0001
//after shift
val = 10000

notice the 1 moved to the right 4 times. The left shift operator( >> )
works similar except it shift all bits to the left x amount of times.

mrnutty 761 Senior Poster

you studied quantum mechanic, Grim?

mrnutty 761 Senior Poster

1) Use code tags.
2) #include "blah.h" tells compiler to look into the project directory
for the file. Libraries like string and cctype are not in your directory
and so use #include<blah> syntax.
3) Whats your problem?

//adjusted a little
#include<stdio.h>
#include<conio.h> //non standard
#include<process.h>
#include<ctype.h>
#include<string.h>
#include<io.h>
#include<fcntl.h>

#define length 1

struct StudentInfo
{
    char studentid[8];
    char lastname[15];
    char firstname[15];
    char middlename[15];
    char gender[6];
    char birthdate[15];
    char age[3];
    char contactno[15];
    char guardian[30];
    char address[120];
};

struct tmp
{
    char studentid[8];
    char lastname[15];
    char firstname[15];
    char middlename[15];
    char gender[6];
    char birthdate[15];
    char age[3];
    char contactno[15];
    char guardian[30];
    char address[120];
};

StudentInfo var[length];
//GLOBAL IS BAD
int rea = -1, top = -1;

FILE *ptr;

void refresh()
{
    fclose(ptr);
    ptr = fopen("c:\\file.txt","a+");
}

int filesize()
{
    int des;

    des=open("c:\\file.txt",O_RDONLY,0);
    des=lseek(des,0,SEEK_END);

    return length;
}

int getNoOfRecords()
{
    return(filesize()/(sizeof(struct StudentInfo)));
}

void addStudentRecord()
{
    char ans;
    int x,y;
    clrscr();
    tmp s;

for(y=0; y<8; y++)
{
    s.studentid[y]='\0';
}
for(y=0; y<15; y++)
{
    s.lastname[y]='\0';
    s.firstname[y]='\0';
    s.middlename[y]='\0';
    s.birthdate[y]='\0';
    s.contactno[y]='\0';
}
for(y=0; y<6; y++)
{
    s.gender[y]='\0';
}
for(y=0; y<3; y++)
{
    s.age[y]='\0';
}
for(y=0; y<30; y++)
{
    s.guardian[y]='\0';
}
for(y=0; y<120; y++)
{
    s.address[y]='\0';
}


printf("\n\nADD STUDENT RECORD MODULE\n\n");

if(top!=length-1)
{
    printf("Student ID: ");
    gets(s.studentid);
    printf("Lastname: ");
    gets(s.lastname);
    printf("Firstname: ");
    gets(s.firstname);
    printf("Middlename: ");
    gets(s.middlename);
    printf("Gender: ");
    gets(s.gender);
    printf("Birthdate: ");
    gets(s.birthdate);
    printf("Age: ");
    gets(s.age);
    printf("Contact Number: ");
    gets(s.contactno);
    printf("Guardian: ");
    gets(s.guardian);
    printf("Address: ");
    gets(s.address);
    printf("\n\n");
}

    printf("Do you want to save<Y/N>?\n\n");
    ans = getche();
    
if(toupper(ans)=='Y')
{
    strcpy(var[top+1].studentid,s.studentid);
    strcpy(var[top+1].lastname,s.lastname);
    strcpy(var[top+1].firstname,s.firstname);
    strcpy(var[top+1].middlename,s.middlename);
    strcpy(var[top+1].gender,s.gender);
    strcpy(var[top+1].birthdate,s.birthdate);
    strcpy(var[top+1].age,s.age); …
mrnutty 761 Senior Poster

A char cannot hold "312,000". You are probably thinking about
an array of chars, or a string. Use something like this :

#include <iostream>
#include <string>
#include <sstream>

using namespace std;

string deleteChar(string str, char charDelete = ','){
	size_t pos = str.find(charDelete);
	if(pos == string::npos) return str;
	str.erase( pos, 1);
	return str;
}
size_t convertFromString(string strNum){
	stringstream converter;
	size_t value = 0;
	converter << strNum; //insert string into our stream
	converter >> value; //extract data into our variable
	//check if conversion was good
	if(converter.fail() ) throw std::exception(" Error converting " );
	return value;
}
size_t myConvert(string strNum){

	while(strNum.find(',') != string::npos) //while comma is there
		strNum = deleteChar(strNum); //delete the comma

	size_t value = convertFromString(strNum); //convert string to size_t

	return value;
}
int main ()
{	
	size_t value = myConvert("1,000,000");
	cout << value * 2 << endl;

	return 0;
}
mrnutty 761 Senior Poster

>> Computers can't generate random numbers the way our mind does

Citation please? I am interested on where you got this info.

mrnutty 761 Senior Poster

01011001 01101111 01110101 00100000 01101011
01101110 01101111 01110111 00100000 01111001
01101111 01110101 00100000 01100001 01110010
01100101 00100000 01100001 00100000 01100111
01100101 01100101 01101011 00101100 00100000
01110111 01101000 01100101 01101110 00100000
01111001 01101111 01110101 00100000 01100010
01101111 01110100 01101000 01100101 01110010
00100000 01110100 01101111 00100000 01110010
01100101 01110000 01101100 01111001

Toche'. I replied just 4 u.

mrnutty 761 Senior Poster

01011001 01101111 01110101 00100000 01101011
01101110 01101111 01110111 00100000 01111001
01101111 01110101 00100000 01100001 01110010
01100101 00100000 01100001 00100000 01100111
01100101 01100101 01101011 00101100 00100000
01110111 01101000 01100101 01101110 00100000
01111001 01101111 01110101 00100000 01100010
01101111 01110100 01101000 01100101 01110010
00100000 01110100 01101111 00100000 01110010
01100101 01110000 01101100 01111001

Toche`, I replied just 4 u.

mrnutty 761 Senior Poster

I actually like chrome. I use it the most.

mrnutty 761 Senior Poster

Yea, its not ideal and does not belong there. I tried to show how to
use some of the material in C++. Usually, one can use Cosine, if the String
is a number. For example.

String str("3.14");
cout <<  str.Cosine();
mrnutty 761 Senior Poster

I think I am one of few without a Facebook. Even my uncle has one.

mrnutty 761 Senior Poster

Whats up with the edit function ? I can't edit my own code ?

Anyways the private bool _checkIfIsDigit()const should be :

bool _checkIfIsDigit()const{
		size_t indx = 0;
		if( (*this)[0] == '-') indx = 1; //check for negative
		for(; indx != size(); ++indx){				
			if(!isdigit((*this)[indx]) && (*this)[indx] != '.') return false;
		}
		return true;
	}
mrnutty 761 Senior Poster

Some background.

We all used the string class, but some of you might not know that
string is just a typedef of basic_string.
In fact here is the typedef you might find when looking in the XString library.

typedef basic_string<char, char_traits<char>, allocator<char> >   string;

This code snippet shows you how to use basic_string to your
advantage. It has almost the same functionality as the string library
but it adds some functionality. It has little error checking. Again this
is shown as an example to learn from. Here is a list of things to
keep in mind :

- template class
- inheritance
- pointer function
- const correctness
- template functions
- scoped namespace
- assert function
- use of typedef

mrnutty 761 Senior Poster

Look into stl's list

mrnutty 761 Senior Poster

I am not sure if you noticed, but the verb form you want is reminisce. Just to let you know, I'm not really anal just thought I could help you out if grammar is not your strong point.

Thanks. I'm more of a math guy then a English one. Plus English is my
secondary language.

mrnutty 761 Senior Poster

>> You need to simulate an array with a pointer and dynamic memory

Better yet, you should use the standard containers. Depending on your
situation, certain one will be better suited. But Below I will give an
example of how to use std::vector to simulate a variable sized array.

#include <iostream>
#include <vector>

using namespace std;


struct CTest{
	CTest(int i = 0)
	{
		static size_t cnt = 0;
		cout <<"Class # " << (++cnt) << " with value : " << i << endl;		
	}	
};
int main ()
{
	vector<CTest> Array;

	int size = 0;
	
	cout<<"Enter size : ";
	
	cin >> size;
	
	//resize the size to what the user enters.
	Array.resize( size , CTest(1) ); //Prints Class # 1 with value 1

	//iterate over the array
	for(int i = 0; i < Array.size(); ++i)
		Array[i] = CTest(10+i);/* do stuff */ //Prints Class # (2+i) with value (10+i)

	//no need to delete  the vector;
	
	return 0;
}
mrnutty 761 Senior Poster

Giggidy Giggidy Giggidy
- Family Guy, Quagmire.

mrnutty 761 Senior Poster

>> Who would design a page with a bright red background and white text

Obviously reptilians! Their visions can handle colors better than we can.

mrnutty 761 Senior Poster

There is also Eclipse.

mrnutty 761 Senior Poster

>> Their cubes are: 1, 4, ..., 81

no their cubes are 1^3, 2^3 , 3^3 ... 9^3

mrnutty 761 Senior Poster

My friend passed it onto me and its only right I pass it onto you .
Its the most simple game. Can you pass all 4 levels?

mrnutty 761 Senior Poster

I chose to use the goto loop to setup the k counter. is there a better way to setup a counter i basically want the program to iterate 13 times before it goes to the next step.

Yes, thats what loops are there for, to iterate certain amount of times.

mrnutty 761 Senior Poster

>> If you vote yes then animals should have the same rights as humans

As a result of the survival of the fittest, its impossible for animals
to have the same rights as humans, unless we don't wan't to survive or
commit some fallacy.

mrnutty 761 Senior Poster

For every C++ program, you need a starting point, and that starting point
should be either "int main()" or "int main(char *arg, char *argv[])"

Here is a complete C++ program :

#include <iostream>
using namespace std;

int zero(){
   return 0;
}
int main()
{
  int x = zero();
  
   cout << x << endl;

    return 0;
}
mrnutty 761 Senior Poster

>>At 19, you're WWWWAAAAYYYYY too young to say "Back in my day...".

It was just a saying. I don't literally say it. Although I do reminiscent about
my childhood where I had no responsibility.

mrnutty 761 Senior Poster

>> typedef this templated structure

Why? Just name your class appropriately. And you will be fine. Also check this out for more info.

mrnutty 761 Senior Poster

For your print maze do this instead,

void printMaze(char maze[100][100],int mazeSize)
{
    for(int i = 0; i < mazeSize; i++)//printing the maze
		{
			for(int j = 0; j < mazeSize;j++)			
				cout << maze[i][j] << " ";			
                   cout << endl;
		}
}

As for your problem, where does the player start from ? I don't see
a way to get in the maze from outside, so I figure there is a starting
point.

mrnutty 761 Senior Poster

when you say, "back in my day...".
--------------------------------------------------------
Just for curiosity, whats the age group here in Daniweb? Anyone want
to tell their age? I'm 19.

mrnutty 761 Senior Poster

Ok, thats a better argument. At least I gained something out of this
conversation. I'm still learning as I go, because I just started "learning"
this C++ about a 1.5- 2.0 years ago. Thanks for clearing that up a bit more.

mrnutty 761 Senior Poster

>> Do you have any particular reason for that guideline
I rather not have member variables public rather than private. But
occasionly I tend to use structs for private inner classes or as an helper. But judging what he is doing he should use classes.

mrnutty 761 Senior Poster

>> what is you're ideas , please analyze that flaw of wolfram alpha
>> The answer is so big the not even 64-bit can store the number
No sh*t. Its approximately 392,717,716,282 digits long. There is no flaw
in wolfram. Its made my brilliant mathematicians and great programmers.
No offence but I am sure you probably won't find any problem with it.

mrnutty 761 Senior Poster

Yes, but use classes. Prefer classes to structs.

template<typename Type>
class CStack
{
public: 
 const static int MAX = 100;
private:
Type _array[MAX];
size_t currentMaxIndex;
};
mrnutty 761 Senior Poster

Using the stringstream will make it easier. Or you can use substr as well, but will be more work.

mrnutty 761 Senior Poster

sure whats the question, exactly?

mrnutty 761 Senior Poster
01011001 01101111 01110101 00100000 01101011 01101110 01101111 01110111 00100000 01111001 01101111 01110101 00100000 01100001 01110010 01100101 00100000 01100001 00100000 01100111 01100101 01100101 01101011 00100000 01110111 01101000 01100101 01101110 00100000 01111001 01101111 01110101 00100000 01100001 01110010 01100101 00100000 01101001 01101110 01110100 01100101 01110010 01100101 01110011 01110100 01100101 01100100 00100000 01101001 01101110 00100000 01101011 01101110 01101111 01110111 01101001 01101110 01100111 00100000 01110111 01101000 01100001 01110100 00100000 01110100 01101000 01101001 01110011 00100000 01110011 01100001 01111001 01110011 00101110
mrnutty 761 Senior Poster

>>// output: 4 (?!) Shouldn't this be an error?
It is. And its a bad one, which went undetected in a sense.