mrnutty 761 Senior Poster

You know you are a geek when you are a member of a programming forum :)

mrnutty 761 Senior Poster

You have this :

return 0;
system("PAUSE");
return EXIT_SUCCESS;

Take out the return 0 , since return EXIT_SUCCESS is the same thing.

So you should now have this :

system("PAUSE");
return EXIT_SUCCESS;
mrnutty 761 Senior Poster

Good. Now try to be more organized and start learning classes. Once you
have a "good" grasp, convert the code into objects.

mrnutty 761 Senior Poster

Have a test condition in your for loop.

In psuedocode :

for i = 0 untill MAX{
pick1 = random number
pick2 = random number
while(pick2 == pick1 ) pick2 = another random number
pick3 = random number
while(pick3 == pick2 or pick3 == pick1) pick3 = another random number
}
mrnutty 761 Senior Poster

They have given you the answer, but let me expand on that :

Your prototype for fillArray is this :

int   fillArray(int);//Trying to make a fn that fills an array

What does that mean ? It says that fillArray takes an int variable and
returns an int variable. What you want it to say is that fillArray
takes a int array, and a int variable and returns nothing.

So it would be something like this :

void  fillArray(int anArray[], int itsSize);

Again, that means that fillArray takes an int array and its size as a
variable. Then all you have to do is make sure its defined.

mrnutty 761 Senior Poster

This is not a function call :

bubbleSort(int * Array, int SIZE);

this is :

bubbleSort( Array,  SIZE);
mrnutty 761 Senior Poster

1) Too much comment.

2) That is not how to call a function :

bubbleSort(int * Array, int SIZE);

it should be

bubbleSort(Array,Size);

3) you bubble sort is wrong, j should start out as i+1 until the SIZE.

4) You aren't populating your array with random numbers, here is one
way to achieve this :

for(int i = 0; i < SIZE; i++)
      Array[i] = rand()%SIZE;  // random number from 0->SIZE-1

5) You will want to seed the Random number generator like so at the beginning of main :

srand( time (0) );

To use the time function, you need to add this to your header :

#include<ctime>

The good thing is that you have some code, you used code tags, and
you are on the right track.

mrnutty 761 Senior Poster

You can either use standard containers or use dynamic arrays. I will show
you how to use both :


using std::vectors

#include<iostream>
#include<vectors>

using namespace std;

int main()
{
      vector<int>  Array;

      cout<<"Enter the array size : ";
      int Size = 0;
      cin >> Size;

    Array.resize(Size); 

    //now populate

    for(int i = 0; i < Array.size(); i++)
           Array[i] = i;
    
    bubbleSort(vector); //where bubbleSort is on you have created

   return 0;
 
}

I suggest the above than the one below :

using dynamic array :

#include<iostream>
using namespace std;

int main()
{
    int * Array;
    cout<<"Enter array size : ";
    int Size =0;
    cin >> Size;
   
    Array = new int[Size]; //allocate memory for our array

   for(int i = 0; i < Size; i++)
           Array[i] = i;

     bubbleSort(Array, Size); //bubbleSort it
   return 0;
}
mrnutty 761 Senior Poster

The elses increase efficiency, but my point is " if (convMeth = 2) " always evaluates to true, so that if block will always execute. Adding elses in the existing code will definitely prevent both cases from executing, but if a third was later added, the logic would never get beyond the second test.

Yep, so what are you trying to achieve again?

mrnutty 761 Senior Poster

Do you understand this ?

if( something) { do something }

else if( it is something else ) { then do something else }

else if( it is something else) { then do something else }
mrnutty 761 Senior Poster

look up std::merge

mrnutty 761 Senior Poster

Well if you insist to do it that way then you can use the exponent
properties:

2^6 = 2^3 * 2^3 = 2^5 * 2^1

2^ 5 = 2^ 2 * 2^3

1024 ^ 50 = 

(2^10)^50 = 

2^500 = 2^100 * 2^100 * 2^100 * 2^100 *2^100

2^100 = 2^ 50 * 2^50

2^50 = 2^20 * 2^ 30

2^20 = 2^10 * 2^ 10

2^ 30 = 2^20 * 2^10

2^10 = 2^5 * 2^5

2^5 = 32

now just plug back in x amount of times and you have a whole mess.
mrnutty 761 Senior Poster

Recursion is a bad idea here. But if this is what you want :

String str = "vertical";
printVertical(str);

and if the output should be :

v
e
r
t
i
c
a 
l

Then your code shouldn't be hard.

do something like this :

static void printVertical(String s, int index)
{
    //check for error in index i.e check its bounds
   //print out string at location, index
   //recurse with s passed and index+1
}
mrnutty 761 Senior Poster

I disagree, I was using car AS a base class, seeing as the question "what kind of car do you drive?" would apply, regardless of whether or not you drove a truck, or an SUV, or a minivan.

However, that's truly irrelevant to the point. I wasn't trying to 'critique' his work per say, I was trying to ensure he truly understood the idea of inheritance.

Just because a car is composed of similar things that a truck is
composed of does not mean a truck is a car( or the other way around).
It however suggests that they are composed of similar things, thus
each of their class should inherit from a base class that encapsulate
those similarities.

mrnutty 761 Senior Poster

I would say you know your a computer geek when you have done over 1000 posts on daniweb. lol That's me alright.

Btw, how do you calculate to the power without a calculator? eg. 1024^50 using only addition, subtraction, multiplication and division. Just wondering as it would have been handy in the past without doing endless multiplication.

Addition,subtraction,multiplication and division ? What ?

I can do without that! Just look here :
secret

mrnutty 761 Senior Poster

Get the input as a string and append those strings :

cout<<"Enter a hex number : ";
string s1, s2;
cin >> s1 >> s2;
s1 += s2;
cout<<s1;
mrnutty 761 Senior Poster

To start off with, based on your example, I'm not sure you've got the general idea of inheritance. In general, you want to inherit from another class if the class you're building has all the attributes of the class you're inheriting from, plus some unique to this child class.
If that confuses you, let me give you an example.

class Car
{
//a car has four wheels.
// a car has an engine
}

class Truck: public Car
{
//a truck ALSO has four wheels
//a truck ALSO has an engine
//a truck has a bed
}

so, you wouldn't want to inherit a Week object from a Day object, because you can't, in essence, say that a Day IS A Week.

On to your later question. If you were to say weeks[0] = new Day(); then yes, it would create a day object, but by accessing it through the weeks array, you could only access the attributes of the "week" portion of it that was inherited.

If you are going to critique his work, then give a better example.
Car does not have a "is a" relationship to truck. Instead you should
have a abstract base class and have both of them inherit from it.

mrnutty 761 Senior Poster

1) Why ?

2) need compile time variable meaning there will be a fixed amount
of inputs to get

3) Need to implement your own sorting method and use it inside main,
so technically it won't be a function. If not then you will need a lot
of if/else or you can use trees.

4) Bad Idea.

mrnutty 761 Senior Poster

google cctype header. Its really useful.

mrnutty 761 Senior Poster

How about you show some code, so we can try to help you,
although monte carlo problem should be slow to execute as it is quite
easy to implement.

mrnutty 761 Senior Poster

floats are made for spaced optimization, it does not necessarily have to
be faster than double, especially in a 64bit CPU.

mrnutty 761 Senior Poster

You have a vector of int pointers that do not point to any memory.
Try allocation memory first.

mrnutty 761 Senior Poster

Think of main as a variable. And your function takes a variable a well.
But the variable is not normal, its a function. A function can be passed to another function like a variable. You just need proper prototype.

Compare :

void Foo(int var); //takes in a int variable
void Foo2( int(*pF)() ); //takes in a int function with no parameters

You can also use typedef to make the function pointer look more
natural.

mrnutty 761 Senior Poster

First initialize your variables.

Average = totalSum/totalElement.

Thus totalSum should be computed first and then divide it by the
array size.

mrnutty 761 Senior Poster

How about you warp your code into code tags, correctly.

Then comment on each line of code, so we can see what you are thinking.

mrnutty 761 Senior Poster

I think whats more important is what the safer way.

mrnutty 761 Senior Poster

Don't forget code tags. It makes it easier for us to help you.

mrnutty 761 Senior Poster

It would be better if you just let the overloaded operator work like this

MyClass A;
//initialize A
cout<< A[0].someGetFunc();

Do you know how to accomplish this?

mrnutty 761 Senior Poster

make initCheck a static method. Do you know what the term static mean
in the context of programming?

mrnutty 761 Senior Poster

You know you are a geek you find it more natural to count numbers
in the power of 2 then decimal.

William Hemsworth commented: nice thread. +0
mrnutty 761 Senior Poster

what is it supposed to be?

mrnutty 761 Senior Poster

Use an external library to handle musics and sound. I would suggest
openAL (Google it).

mrnutty 761 Senior Poster

Input = cin
x is a float
y is a int
r is a int

for i to y means :

for(int i = 1; i < y; i++)
{
   //code goes here
}

The "code goes here" part is result = result * i;

mrnutty 761 Senior Poster

Whats your problem?

mrnutty 761 Senior Poster

Change the && to ||

mrnutty 761 Senior Poster

is it possible to use just a vector instead of vectors of vectors?

mrnutty 761 Senior Poster

Can you be more clearer?

Do you mean how random number works ?

mrnutty 761 Senior Poster

Why do you have 3 loops for a 1d vector?

If you want to emulate it as a 2d then all you need is 2 for loops.

int A[4] = {1,2,3,4};
int B[4] = {1,2,3,4};
int R[4] = {0};

for(int i = 0; i < 4; i++)
{
     for(int j = 0; j < 4; j++)
         R[ j + 4*i] = A[j + 4*i] * B[j + 4*i];
}

Its better to make a function that converts (j+4*i) into a 2d index so it becomes more readable.

mrnutty 761 Senior Poster

use SingletonVector::vBooks.push_back(b);

pac-man commented: Thanks for the replies mate +1
mrnutty 761 Senior Poster

Tell me if you see a problem here :

char an;
cout << "Please enter the operation you want" << endl;
cout << "Press 1 for addition" << endl << "Press 2 for subtraction" <<
endl << "Press 3 for division" << endl << "Press 4 for multiplication"
<< endl;
cin >> choice;
cout << "Please enter the numbers you want to do calculation with" << endl;
while (an = 'y')

Then you say :

cout << "Please enter the numbers you want to do calculation with" << endl;

In which you don't do this :

cin >> a >> b;
mrnutty 761 Senior Poster

>>a problem arises whereby, when I access the vector from a different class, for some reason it "loses" it's contents and is empty?
<<

From what content?

How about you make a adapter class, that wraps vector, and make that
adapter class singleton.

mrnutty 761 Senior Poster

You could use glutBitmapCharacter

Combined with function you can make this :

void renderBitmapString(
		float x, 
		float y, 
		float z, 
		void *font, 
		char *string) {  
  char *c;
  glRasterPos3f(x, y,z);
  for (c=string; *c != '\0'; c++) {
    glutBitmapCharacter(font, *c);
  }
}

That is provided by lighthouse, Their link

Now all you need is a little bit of logic.

For example :

string input = "";

void keyBoard(unsigned char key, int x, int y){ 
    input += key;
   void updateString();
}

and :

void updateString(){
   glutBimapString(0,0,0, GLUT_BITMAP_9_BY_15, input.c_str());
}

You can then call this function also in you draw function.

void drawFunc()
{
    glClear(someBITSGoesHerE);
    glLoadIdentity();
    updateString();
 //blah blah
}
mrnutty 761 Senior Poster

Here is a hint :

********** 10 stars
*********  9 stars
********   8 stars 
*******   7 stars
******  6 stars
***** 5 stars
**** 4 stars
***  3 stars
** 2 stars
* 1 stars
**  2 stars
*** 3 stars
**** 
*****
******
*******
********
*********
********** 10 stars

So you see that they decrease by 1 star until they reach 1 then they
start increment.

so assuming you can separate this problem into 2 blocks, you can
do something like this :

for(int i = 10; i != 1; i--)
     printStars(i); //a function that prints i stars with endl
for(int i = 2; i <= 10; i++)
     printStars(i);

Now what should your printStars look like :
for example if one calls printStars(4) it should output the following :

****

Go ahead and try to devise printStars then you problem becomes much
easier.

mrnutty 761 Senior Poster

Well the top and the bottom are the same so you can just duplicate the
top at the end, and the middle two are the same. I see no reason to
use for loops for this.

mrnutty 761 Senior Poster

>>or some reason it doesn't think accountSum has been initialized so my program won't run
<<

Yea its right, sorry I am in c++ mode.

try :

Account accountSum = new Account();
mrnutty 761 Senior Poster

>>
Add a static method Account consolidate(Account acct1, Account acct2) to your Account class that creates a new account whose balance is the sum of the balances in acct1 and acct2 and closes acct1 and acct2. The new account should be returned.
<<

Break this down :

>>Add a static method Account consolidate(Account acct1, Account acct2) to your Account class
<<

public Account consolidate(Account account1, Account account2)
{ /* Code */ }

Next part of the statement :
>>
Account class creates a new account
<<

public Account consolidate(Account account1, Account account2)
{ 
     Account accountSum;
}

whose balance is the sum of the balances in acct1 and acct2 and closes acct1 and acct2. The new account should be returned.

public Account consolidate(Account account1, Account account2)
{
       Account accountSum;
      accountSum.balance = account1.getBalance() + account2.getBalance();

   //make account1 and account close()
}

See how that works. Break down the question, and it becomes simpler.
So you need to sum the balance, and close account1 and account2.
By the way, You should make account1 and account2 = null when its closed.

mrnutty 761 Senior Poster

Post your code as of now.

mrnutty 761 Senior Poster

call your calc_average inside openFile function.

mrnutty 761 Senior Poster

Ascii Table

They represent the value of a character. For example :

All character from 'a' to 'z is represented by the decimal value 97 to 122.

So a function that would check if a character is a lower case character might look something like this :

bool isLowerCase(char ch){
   //check if the ascii value of ch is between 97 and 122
    return ( ch >= 97 && ch <= 122 )
}
mrnutty 761 Senior Poster

>>xutility(348) : error C2064: term does not evaluate to a function taking 2 arguments

Which line is this from?