mrnutty 761 Senior Poster

1) Create a member variable. To hold the weapon.

class CPlayer{
 private:
 Sprite weapon;
 //...
}

Now create a get and set function for the weapon :

void setWeapon(const Sprite& aWeapon){
 weapon = aWeapon;
}
Weapon getWeapon()const{
 return weapon;
}

Now you need position the weapon and use it accordingly.

mrnutty 761 Senior Poster

First, I'm not sure about this :

/string 
string message = () ;

Do this instead:

string message; //will hold the encoded message

Now your main problem is decryptLetter. This function is fairly simple.
What problem are you having with this exactly?

mrnutty 761 Senior Poster
string fileName = "File";
	string extension = ".txt";
	for(char fileNum = '0'; fileNum <= '9'; ++fileNum){
	 string currentFile = fileName + string(1,fileNum) + extension;
	 cout << currentFile << endl;
	}
mrnutty 761 Senior Poster

Try implementing this .

mrnutty 761 Senior Poster

Maybe this will help you get started :

#include <stdio.h>
int power(int base, int exp){
  //logic goes here
}
int main(){
  int res = power(2,10); //res = 1024
  printf("%i",res);
  return 0;
}
jonsca commented: Putting a C twist on it I see. +4
mrnutty 761 Senior Poster

Do something like this :

class Polynomial{
 private:
 std::vector<int> coeff; //the coefficiants
 public:
 void getInput();
 void printPolynomial();
}

its pretty much similar to yours except I use a vector instead of raw arrays.
Now just implement the input and output functions.

mrnutty 761 Senior Poster

Have you not heard of type casts? foo((char*)client_message[i].c_str()); or foo( const_cast<char*>(client_message[i].c_str())); But you have to be careful about casting away the const, especially if function foo() wants to modify the contents of the string.

I strongly advise against doing that. If you need to cast away a const, then its a design problem. c_str() returns const char* for a reason.

mrnutty 761 Senior Poster

why do you have Sleep(...) ?

and normally "if(Dict.is_open()) " is used as a error checker. There is a lot of problems with you code. Instead of listing them all, I will show you a sample program
and you should contrast.

#include <iostream>
#include <fstream>
#include <string>
#include <windows.h>
using namespace std;

int main () {
  string line;
  ifstream Dict ("C:/Users/Brandon/Desktop/Programs C++/Dictionary.txt"); //file to read
    ifstream file ("C:/Users/Brandon/Desktop/test.txt", ios::out | ios::app | ios::binary); //file to write

  if (!Dict.is_open()) { return -1; /*error */ };
  if (!file.is_open()) { return -1;/ /*error */ };

   while(!Dict.fail()){ //while we can read the file
      getline (Dict,line); //get the current line                   
      cout << line <<" "; //print line to screen
      file << line ; //write line to file
     }
  return 0;
}

I have not compiled this, but you should get an idea.

mrnutty 761 Senior Poster

If you can return an iterator, but I think that would be out of your scope. So
instead return a index counter, although I am not sure how good thats gonna do you.
Try something like this :

int floatlist::search(double x)
{
    int index = -1;
    listnode *p = head;
    while (p != NULL)
    {
        ++index;
        if (p->value == x)
               break;
        else
            p = p->next;     
             
    }
    return index;

Then you can check your code, if the search method returns -1, then its not in the
list else it is.

mrnutty 761 Senior Poster
mrnutty 761 Senior Poster

You are looking for std::vectors. Here is an example :

std::vector<int> aList(2,0); // 0 0  [size = 2]
aList[1] = 1; // 0 1  [size = 2 ] 
aList.push_back(2);   // 0 1 2   [size = 3]
aList.pop_back();     // 0 1     [size = 2]

You can also simulate what you want using dynamic array, but i suggest otherwise.

mrnutty 761 Senior Poster

if condition and else condition is there....i want to display
hello world.

<?
if(Condition)
{
echo "hello";
}
else
{
echo "world";
}
?>

then my frnd asked to me what the condition should write in if condition to display "hello world".

With that code its not possible. Only one of the echo will execute because if(condition)
has only 2 answers, true or false. If its true then echo "hello" else "world". As
suggested my previous post, you might try compound boolean expression.

mrnutty 761 Senior Poster

What its asking you is to make a walk through table -- a step by step table
where each row corresponds to each iteration of the loop. Here, I'll get you started

Given this code :

int c = 0, sum = 0;
while (sum < 8) {
  c++;
  sum += c;
}
 cout << sum;

a walk through table might look like this to start :

iteration # , value of c , value of sum
---------------------------------------
   0             0               0
   1             1               1
   2             2               3
   3             3               6
   .             .               .
   .             .               .
   .             .               .

I think that is what its asking for.

mrnutty 761 Senior Poster

There are many ways you can approach this problem. I would just notepad to first
sort the file and then read it in and do whatever I need to do with it. But I assume
this is for learning purposes. So here is some things you can do :

1) Get the length of file and create an array dynamically and read it and doStuff();
2) Use vectors and get the input from both files. Then use std::sort to sort the vector
3) Append file#2 to file#1, then read it into a vector, then use std::sort
4) ... come up with your own idea

Just pick one and start.

mrnutty 761 Senior Poster

Here is a site to practice on, http://www.projecteuler.com

mrnutty 761 Senior Poster

Here is a way to do it using metaprograming. That way you get the result before you
even start the program.

#include <iostream>


template<int binarySequence>
struct Binary{
	enum{ result = Binary<binarySequence/10>::result << 1 | binarySequence % 10 };
};
template<>
struct Binary<0>{
	enum{ result = 0 };
};

int main(){		
	using namespace std;
	cout << Binary<1>::result << endl; // outputs 2^0
	cout << Binary<10>::result << endl; // outputs 2^1
	cout << Binary<100>::result << endl; // outputs 2^2
	cout << Binary<1000>::result << endl; // outputs 2^3
	cout << Binary<10000>::result << endl; // outputs 2^4
	cout << Binary<10100>::result << endl; // outputs 20

}

I admit, that the formula used is not credited to me. Although the above works.
It does not have a error checking, for input that does not consists of 1's and 0's.

Isn't this so cool? You get the answer before you even run your program!

mrnutty 761 Senior Poster

I don't know if its right. But I would suggest to apply the euler method, or better
yet, the RK4 method. Google it.

mrnutty 761 Senior Poster

Actually, I never seen that before. Usually I just call the function w/o the return
statement. I think you should omit the "return" statement on line 8 and 17, because
that might confuse a reader thinking that it actually returns something.

mrnutty 761 Senior Poster

I am not sure what you are asking exactly, but I'll take a stab at it, say you
want to measure the time it takes for a specific part of your program to execute.

To get better results, you might want to use QueryPerformanceCounter, rather than clock. But I'll show you an example using the clock function :

#include <iostream>
#include <ctime> //for clock

using namespace std;

int main(){ 

	srand(time(0));

	time_t startTime = time_t();
	time_t endTime = time_t();
	
	const int SZ = 100*100*10;

	long Array[SZ];
	
	startTime = clock(); //start counting time
	for(long i = 0; i  < SZ; ++i){		
			Array[i] = (rand() << i % (i+1))*1.0/RAND_MAX * (rand() >> 1);
	}
	endTime = clock();

	cout << "Time took for the loop to execute was : ";
	cout << endTime - startTime <<" milliseconds = ";
	cout << (endTime-startTime)*1.0/CLOCKS_PER_SEC << " seconds\n";

	return 0;
}
mrnutty 761 Senior Poster

Here are some although googling would help you get more problems :

1) Create a program that checks if the input is odd or eve
2) Create a program that checks is a power of 2
3) Create a program that asks the user for a positive even number, if thats not supplied, then throw an error
4) Create a program that compares 2 strings and outputs its max
5) Create a program that has the user enter 2 numbers and outputs its max, min, and everage
6) Do #5 for 3 numbers then 4 numbers then 5

mrnutty 761 Senior Poster

what was the best moment of your life so far??
common start sharing ur memories here!!! :)

When I lost my virginity.

mrnutty 761 Senior Poster

When I first lost my virginity.

mrnutty 761 Senior Poster

>> But before adding the two matrices: m1 and m2 , their destructors gets called
why do you think so ?

mrnutty 761 Senior Poster

What would you have done differently? I am open to any and all suggestions.

Well you can make your code more concise.

template<typename StartItr, typename EndItr>
bool isPalin(StartItr start,EndItr end){
	assert(start <= end);		
	if(start == --end) return true;
	while(start < end && *start++ == *end--) continue;
	return (*--start == *++end);
}

But one might be able to program this using metaprograming technique, and
be able to find out whether an input is a palindrome during compile time.

mrnutty 761 Senior Poster

Yea I know. This design is really annoying.

mrnutty 761 Senior Poster

What do you guys think of this new daniweb design? Personally, I'm not
very fond of it. The simpler the better. I just don't like the design. It
needs more "flavor" or something. Idk, what do you guys think?

mrnutty 761 Senior Poster

Nice post. Although I would have done some things different, the idea
is good.

mrnutty 761 Senior Poster

First create a skeleton, maybe something like this :

// include needed libraries
//...

int toDifferentBase(int number, int originalBase, int newBase){
  //code here
}

int main(){
  //test here
}

Now your problem now is to implement toDifferentBase.
The easiest way is to convert the input into base 10. Then convert
that base 10 number into newBase number.

mrnutty 761 Senior Poster

>>**This is my first post as I JUST joined daniweb ^^ <<

Welcome :) We're glad to have you apart of us.

why isn't this defined ?

Bible::Bible(string nam, int chapt, int vers, string testa, string txt) //Initialize to any size
mrnutty 761 Senior Poster

Yea, if this is what you mean :

#include <iostream>
#include <vector>
#include <string>
using namespace std;

typedef string Type;

int main(){

  std::vector<Type> msg(2,"a");
  std::vector<Type>::iterator itr = msg.begin();
 
  while(itr != msg.end()){ 
	  cout << itr->data() << endl; 
	  ++itr; 
  }
}
mrnutty 761 Senior Poster

I wonder if you anticipated this kind of response?
http://clusty.com/search?query=virtual+function&sourceid=Mozilla-search

I wonder if he anticipated this kind of response too?

mrnutty 761 Senior Poster

For this one :

If c >= 17 Then
            PictureBox17.Location = PictureBox16.Location
        End If

        If c >= 16 Then
            PictureBox16.Location = PictureBox15.Location
        End If

        If c >= 15 Then
            PictureBox15.Location = PictureBox14.Location
        End If

        If c >= 14 Then
            PictureBox14.Location = PictureBox13.Location
        End If

        If c >= 13 Then
            PictureBox13.Location = PictureBox12.Location
        End If

        If c >= 12 Then
            PictureBox12.Location = PictureBox11.Location
        End If

        If c >= 11 Then
            PictureBox11.Location = PictureBox10.Location
        End If


        If c >= 10 Then
            PictureBox10.Location = PictureBox9.Location
        End If
        If c >= 9 Then
            PictureBox9.Location = PictureBox8.Location
        End If
        If c >= 8 Then
            PictureBox8.Location = PictureBox7.Location
        End If
        If c >= 7 Then
            PictureBox7.Location = PictureBox6.Location
        End If
        If c >= 6 Then
            PictureBox6.Location = PictureBox5.Location
        End If
        If c >= 5 Then
            PictureBox5.Location = PictureBox4.Location
        End If
        If c >= 4 Then
            PictureBox4.Location = PictureBox3.Location
        End If
        If c >= 3 Then
            PictureBox3.Location = PictureBox2.Location
        End If

You can compress it using a loop :

for(int c = 17; c >= 3; --c){
 PictureBox[c].location = PictureBox[c-1].location;
}

Do the same with the other.

mrnutty 761 Senior Poster

And lets be honest, there are people that just fall under the bell curve.
Sometimes, they just either
1) Don't put in the time to learn
2) Give up after getting confused
3) Or just try to pass the class, w/o a care in the world of the subject.

mrnutty 761 Senior Poster

In java you do not need put a semicolon after the class deceleration. In
C++ you need it. So this part :

#define FERMATH
#ifndef FERMATH

#include <iostream>
#include <cmath>

using namespace std;

class Fermat {
        private:
                long prime p;
        public:
                Fermat();
                Fermat(long num);
                long getNum();
                bool isPrime();
};
#endif
mrnutty 761 Senior Poster

Your average.h is Good, nice job.

Now your average.cpp, has a logic error. Think of average.h like it declares
a function prototype. And average.cpp actually defines these functions.

The logic error in your average.cpp :

#include "average.h" //good

using namespace std; //does not need this since average.h already has this, but is a good practice

float calculateAverage(int numberInputs[], const int size) //function definition  //good now you define the function you declared in average.h
{
	int sumOfTotalInputs = 0; 
	int i = 0;
	int avg;
       /*--------Below is your logic error--------------------*/
	sumOfTotalInputs += numberInputs[i]; //calculation to get the total sum of numbers from user
       /*----------------------------------------------------------*/
	avg = sumOfTotalInputs / size;  //to find average 

    return average;
}

the place where I marked logic error is your first problem. You need to go through the loop and add up all the values like so :

for(int i = 0; i < size; ++i){
 sumOfTotalInputs += numberInputs[i];
}

Now your other problem is inside your main.
This code

int [NUM_OF_INPUTS] = [0];

is not how to declare an array, this is how you declare an array :

int Array[NUM_OF_INPUTS] = {0};

Then you do not need this part in your main, just delete it :

cout <<"This program will average a group of 5 numbers of your choice." <<endl;
cout <<"\n\nPlease enter 5 numbers: " <<" "<<endl;
//cin >> numberInputs[i]; //<--- do not need this , you have it inside you for loop

Fix those and …

mrnutty 761 Senior Poster

A program that leaves programming to the computer.

I hope thats not invented, because if so, then I'll be out of a job, if I
had one.

mrnutty 761 Senior Poster

What you do is use strings :

string data;
 cout << "Enter the date in MMDDYYYY format: ";
 cin >> date;
 asserCorrectFormat(data); //make sure valid format
 doStuff(data);
mrnutty 761 Senior Poster

Whats confusing about it? Maybe some pics will help :

//initial list
1->2->3->4->5->6

If I put [] around a number then thats the current pointer pointing to.
So the pointer starts pointing to 1 so :

[1]->2->3->4->5->6

Let P1 be the current pointer, then from your psuedocode, we delete
(P1+2). Since our pointer is pointing to 1, we delete (1+2), or the third element, which is 3, so:

//move our pointer two places
1->2->[3]->4->5->6

Now we delete 3. So the list now is :

1->2->[4]->5->6

Notice, the current pointer moves forward, when the element its pointing to gets deleted. Now again, we move 2 places from our
current pointer so :

//move from 4 to two places forward, into 6.
1->2->4->5->[6]

Now we delete the element that the pointer is pointing to, thus :

//delete 6 and move pointer forward
[1]->2->4->5

Since we delete 6, and since this is a circular list, instead of pointer pointing to null, it now loops back to 1.
Now we move the pointer two places forward and delete it, so :

//move two places from 1 and delete that element
1->2->[4]->5

Now 4 gets deleted, and the pointer is now pointing to 5. So,

1->2->[5]

Now move the pointer 2 places, since this is a circular loop, it loops back from 5, when you move forward so, moveing 2 places from 5, we get :

//move two places from 5, and …
mrnutty 761 Senior Poster

No it dosen't matter. You are a computer scientist. But for your own good
I would advice you to take trig based physics. In computer graphics
programmer, you will use more trig and vectors than calculus. Its good if
you know calculus with addition. Anyways, its your choice, why not ask one of your computer science teacher?

mrnutty 761 Senior Poster

Ok, here is the deal. Do you know how to do this with 1 file ?
For example in 1 file, you would do this :

//main.cpp
#include <iostream>
using namespace std;
float calcAverage(int inputs[], const int size); // [1] function prototype
int main(){
 const int NUM_OF_INPUTS = 5;
 int inputs[NUM_OF_INPUTS] = {0};
 for(int i = 0; i < NUM_OF_INPUTS; ++i){
     cin >> inputs[i]; //get the 5 numbers from user
  }
 cout << "Average = " << calcAverage(inputs, NUM_OF_INPUTS) << endl;
}
float calcAverage(int inputs[], const int size) // [2] function definition{
 int sumOfTotalInputs = 0;
 for(int i = 0; i < size; ++i){
   sumOfTotalInputs += inputs[i]; //get the total sum
 }
 //calculate the average, notice average is of type float
 float average= float(sumOfTotalInputs) / size; 
}

Now all you need to do is split the code up, so for example you could do this :

//average.h
void calculateAverage(int inputs[], const int Size); //[1]function prototype
//
//average.cpp
void calculateAverage(int inputs[], const int Size){ //[2] function defintion
  //... code to calculate averge given the array of numbers and its size
}
//main.cpp
int main(){
 const int NUM_OF_INPUTS = 5;
 int Array[NUM_OF_INPUTS] = {0};
 //get inputs from array
 cout << "Average = " << calculateAverage(inputs,NUM_OF_INPUTS)  << endl;
}
mrnutty 761 Senior Poster

You know, this is just a suggestion so you don't have to listen.
These methods :

double dist( Point );
void move( double, double, double );

I wouldn't make put them into the Point interface. Because I feel that
they would be better of decoupled from the interface.

mrnutty 761 Senior Poster

Queue is not the syntax.

To declare a queue in C++ using C++ library, you do this :

queue<int> q1;
queue<float> q2;
queue< ItemType >q3;

For linked list you do this :

list<int> a1;
list<float> a2;
list<ItemType> s2;

Queue and LinkedList are Data Structures for Java, in C++ its , queue<type> and list<type>

mrnutty 761 Senior Poster

whats the errors exactly?

mrnutty 761 Senior Poster

Welcome, we'll be glad to help. Just make sure you read the rules, and use code tags and such.

mrnutty 761 Senior Poster

Using strings, so concatenations will be easier ;

string firstName = "dani";
string lastName = "web";
string fullName = firstName + lastName; //concatenation
string tmp = fullName;
//reverse
std::reverse(fullName.begin(),fullName.end());
if(fullName == tmp){ cout << "Palindrome\n"; }
else cout << "Not Palindrome\n";
mrnutty 761 Senior Poster

use

while(!inFile.fail()){...}
mrnutty 761 Senior Poster

When you do this :

#include "sim.cpp"
using namespace std;

you are not including namespace std, inside sim.cpp, because of the ordering.

Just do this :

#include <iostream>
#include <fstream>
#include <queue>
#include <list>
#include "ItemType.h"
using namespace std;

yo

mrnutty 761 Senior Poster

Why create it when stl already has one for you? Maybe you should give
more information on what you are trying to do.

mrnutty 761 Senior Poster

>>for i = 0 to n-1 do

how long does this loop run for?

>>for j = 0 to (i^2) - 1 do

Realize that this loop runs for (i^2)-1, for EACH i in the loop before this

>>for k = 0 to j - 1

Realize that this loop runs for j times, for EACH j.

mrnutty 761 Senior Poster

Generally you do not want a class doing all of that. A good idea would
be to split up the work so that a class has its minimal objective to fill.
So instead of having the class do everything, split the jobs up. This makes
it more readable and cleaner.