mrnutty 761 Senior Poster

Hi,
So for this we should rather write

for(i= 0; i <sizeof(scores) / sizeof(int); i++)

That does not work once this is not done within the array's scope.

@OP :

just do this :

for i = 0; i < arraySize ++i{
   for j = i+1; j < arraySize; j++
         if array[i] > array[j] 
              swap the two values;
}
mrnutty 761 Senior Poster

First make two variables, sentence1 and sentence2, unless you are
using a period '.' as the end of one sentence.

Use string if possible.

All you need to do is capitalize sentence[0], the first letter.
if its lower case then use the function from cctype, toupper(char).
It returns the uppercased version of the parameter passed.

mrnutty 761 Senior Poster

If your function parameters looks this this :

foo( Type a, Type b, Type c, Type d, Type e, Type f ...

The that suggest that you either need to break up your functions
into more small and compact and readable function or use OOP programming.

mrnutty 761 Senior Poster

Easiest way to do it is with the rand function

mrnutty 761 Senior Poster

An even easier way :Link

mrnutty 761 Senior Poster

Use strings and sstream.

Get the input as strings. For example :

string input = "";
cout << "<enter text > :\t";
getline(cin,input);

Then use sstream to extract words by words, using the space between
them as delimiters.

If you don't know about the sstream, read up on them because they
are handy.

mrnutty 761 Senior Poster

>>I need to check if two provided words doesn't have the same letter in it

By that you mean if two strings are not equal to each other.

Is this case sensitive?

If so then using tolower would be a good idea( or toupper).

Can you use std::strings , instead of c-style strings ?

mrnutty 761 Senior Poster

What you need to do is read character by character.

First check if the student answer key is the same size as the actual
correct answer key. Subtract 2 points for every length difference.
so :

unsigned int differ =  answerKey.size() - studentAnswer[i].size();
if( diff )  studentAnswer[i].grade -= diff * 2

Now you need to compare each answer, character by character.

So use a for loop starting from 0 to the number of students.
Have the sizeDiff check from above, inside the for loop. Now create another nested for loop to check the answer character by character

So your loop could look like this :

for currStudents = 0 to MaxNumOfstudents; currStudents++)
{
    sizeDifference  =  answerKey.size() - studentanswer[currStudent].answer.size();
if( sizeDifference > 0  ) //subtract grade

for key = 0 to key < answerKey.size(); ++key)
{
  if currentStudents answer key is != currentAnswerKey 
         then subtract 2 points
  else add 5 points
 }
}
mrnutty 761 Senior Poster

Ok then, some comments.

Where is ch declared in : ch == lower

Why are you returning in a void function?


Make a toUpper fuction, that takes in a char and returns the upper cased of it.

So for example :

cout << toUpper('a') << endl; //displays 'A';
cout << toUpper('A') << endl; //displays 'a';

Then you can just use a loop for a string to upper it.

string str = "upperThis";
for(int i = 0; i < str.size(); i++)
     str[i] = toUpper(str[i]);
vickietende commented: i think this code is more appropriate but could you care to put the whole code snippet and i could test how it runs +0
mrnutty 761 Senior Poster

Use toupper function in cctype header file.

mrnutty 761 Senior Poster

its not substr, its substr(i);

Plus you are making this way to complicated.

But before I suggest something, Are these assumptions correct :

1) You are comparing the student answer keys with the correct ones.
2) The student has answered all the question.
3) You need to count how many correct the student has.
4) Any more?

mrnutty 761 Senior Poster

Is it CNTRL-D or CNTRL-C ? What system are you running?

[edit]

You can do this :

string x("");

	char END[2] = { 0x04,'\0' };
   
   cout<<"Enter some text (CTRL-D to end): "<<endl;
   cin>>x;
  
	do{	 
		pigLatin(x);   
		cin >> x;
	}while(x != END);
  
	cin.clear();
	while(cin.get() != '\n')
		continue;

   cout<<endl<<"GoodBye!\n"<<endl;

From this

mrnutty 761 Senior Poster
mrnutty 761 Senior Poster

See if this works.

Also since you are using string and cctype header, you should capitalize
on their functions.

I changed your functions a little bit :

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

string pigLatin(string);
bool isVowel(string);
bool isCapital (char);
bool isConsonant (string);
string flipword (string);
string punctuation (string,string &);

int main()
{
   string x("");
   
   cout<<"Enter some text (CTRL-D to end): "<<endl;
   cin>>x;
  
	do{	 
		pigLatin(x);      	  
		cin>>x;
	}while(!cin.eof() && !cin.fail());
  
	cin.clear();
	while(cin.get() != '\n')
		continue;

   cout<<endl<<"GoodBye!\n"<<endl;  
   
   return 0;
}

//****************************************************************
//Function:pigLatin
//Assumption(s): x is a string that contains a single word to be converted to
//pig latin.
//Action(s):Takes the string of x and manipulates it into pigLatin
//****************************************************************
string pigLatin (string x)
{
   char a;
   string puncmark;


   if (isVowel(x) == true)
   {
      x = punctuation(x,puncmark);
      cout << x << "way" << puncmark << " ";
   }

   else if (isConsonant(x) == true)
   {
      x = flipword(x);

   for (unsigned int i = 0; i <= x.length(); i++)
   {
      a = x[i];
      if(isCapital(a) == 1)
      {
         x[i] = tolower(x[i]);
         x[0] = toupper(x[0]);
      }
      x = punctuation(x,puncmark);
      cout << x << "ay" << puncmark << " ";
      x = " ";
   }
   }
  return x;
}

//****************************************************************
//Function:isVowel
//Assumption(s): x is the word that it checked if the first letter is a vowel
//Action(s):Checks if the first letter of the word is a vowel and returns
//a true or false.
//****************************************************************
bool isVowel(string x)   {
	string vowels = "aeiou"; //our vowels
	char v = tolower(x[0]);  //the lowered case …
mrnutty 761 Senior Poster

I assume you call CheckTimer in a loop somewhere right?

mrnutty 761 Senior Poster

Post code. Reading 100mb, will take time.

mrnutty 761 Senior Poster

FirstPerson... I think the OP asked for a nested for loop :P

Oh ok :

for(int i = 0; i !=1; ++i){
    cout << "M"<<endl;
for(int thisIsStupid = 0; thiIsStupid != 0; );         
}
Nick Evan commented: Best. Code. Ever. +10
mrnutty 761 Senior Poster

use std::auto_ptr instead of raw pointers. Use boost's smart pointers
instead of raw pointers. Make sure every call to new is matched with a call
to delete.

mrnutty 761 Senior Poster

???

for(int i = 0; i !=1; ++i)
    cout << "M"<<endl;
mrnutty 761 Senior Poster

You put (Nov 28th 2009):

You put:
<code snipped>
Cya.

He put ( Jul 16th, 2004 ):

hi,
this is the code for switch:
include <stdio.h>
<snipped>

See the problem?

mrnutty 761 Senior Poster

can you give me a sample input and output.

mrnutty 761 Senior Poster

So does that mean that I have a problem with my split_string function?

yes

mrnutty 761 Senior Poster

The error is here : if( vInputs[0] == "spawn" ). vInput[0] is null

mrnutty 761 Senior Poster

Oh I see your problem. Its in this line :

std::vector<BaseEntity> BaseEntity::sm_vEntities = std::vector<BaseEntity>(100000);

You are creating a lot of BaseEntity , in this case not enough. What you
should do is this :

std::vector<BaseEntity*> BaseEntity::sm_vEntities = std::vector<BaseEntity*>(100000);

And change the code accordingly.

And generally , using #define is not a good idea. It leads to problems.

Why don't you just make a getClassName function inside your baseEntity. Or you can make a struct name providesClassName and inherit from that struct.

mrnutty 761 Senior Poster

What is smart pointers?

First, I don't see why you are using #define. That code is not making
it better.

Smart pointers are pointer that are encapsulated in which they
handle the deletion of the object for you, so you don't have to.

In the standard library, they std::auto_ptr, which is ok for now.

mrnutty 761 Senior Poster

what does that mean and how do u do it?

what do you mean? What is stack overflow? Is that what you
are asking?

mrnutty 761 Senior Poster

whats the problem with that code?

mrnutty 761 Senior Poster

If you have a stack overflow then try to allocate on heap. Use smart
pointers if you can.

mrnutty 761 Senior Poster

>>Is this what is required to create an object in Java?
Yes, you have to instantiate every object in java.

>>What do they mean when they say handPhone type?
Its a data type just like a int is a data_type handPhone is a data_type. It just has different capabilities and properties.

>>What do you call the "object" that comes after the new keyword?
Constructor.

>>What do you call these "(??, ??)" in the above example?
Those are the parameters that the constructors take in. Sometimes
it could be nothing, and other times it could be more than zero.

mrnutty 761 Senior Poster

>> C=A+k*C[i+1];

Is this the correct order , i.e :

C = A + ( k * C[i+1] );

What are these values?

mrnutty 761 Senior Poster

sorry for stupid question , but how to read two files at same time ?

You already know how to.

//open file1
//open fil2

while( file1 >> string1 && file2 >> string2 ){
   //compare string and do logic here
}

Now if they are different length then you have to do something a
little extra.

mrnutty 761 Senior Poster

Yes, use string.

If not, then create a variable for the left side before t, then a variable for the right side after t. Then concate left and right to make a new c-string.

mrnutty 761 Senior Poster

here is puedo code :

#include<iostream>
using namespace std;

int main()
{
     //create a variable called sum = 0;
    // create a variable called max = 0;
   //get user input for the max amount
  // make it equal to max
  
  //for i  = 0 to max
      //sum = sum + i;

  //print out sum
   return 0;
}
mrnutty 761 Senior Poster

You need to download and install the Java JDK. Create a project in Visual Studio and delete the automatically generated Class file. Add a new text file. This text file can be used to write any standard Java code. Once again, add another text file called Compile.bat and leave it empty. Go to Tools > External Tools and add a new enty and call this one Javac, you need to make sure that you set the command path to your Compile.bat file and the project directory should be set to the ProjectDir macro path. Click on Use Output Window and put the following in your Compile.bat file:
del Output /S /Q
2.mkdir Output
3.javac *.java -d Output
4.cd Output
5.start java MyApplication

Modify your java application file so that you have a System.in.read() call at the end.

So we are almost finished, click on Tools -> Javac and watch your application compile.

Yea I know that method, but its hard to use the debugger. I
realized that java was discontinued with visual after 05. Thanks
for the input though.

mrnutty 761 Senior Poster

Hi!

I mean the sum of all numbers, not the quantity.

Thanks in advance!

//Adam

Then you do understand the question. So start at it.

mrnutty 761 Senior Poster

don't use the sqrt function. compare the squared distance.

mrnutty 761 Senior Poster

Do you have a sample run? Is it something like this you think :

Enter n : 10
From [0,10] there are 11 different numbers.
mrnutty 761 Senior Poster

Can you use vectors instead of arrays?

mrnutty 761 Senior Poster

To use the copy command for a 2d vector, you would have to copy each
row into the array, not efficient to make so many calls if a few for loops
would do.

mrnutty 761 Senior Poster

Talk about classes, inheritance, polymorphism, generic meta programming, virtual and pure virtual functions, operator overloading...
and also about the potentially bad problems like "multiple inheritance" and the ways to solve it.

mrnutty 761 Senior Poster

You don't have to manipulate the array after being sorted.

You can use a for loop to start from 1 to the array size to show the array. This would disclude the last element. Of course you need to see a 0 at the beginning, so before the for loop just show a 0.

mrnutty 761 Senior Poster

What you are doing is reading the first file and then reading the seconds file. Read both the files at the same time.

mrnutty 761 Senior Poster

So you want to consider only the even row and column. The see if that
even row or column is a even number, if so set it to 0 else do nothing?

mrnutty 761 Senior Poster

>>x^2 + 0.17714x -2.5147583
with k = 1.4997

What does the k represent ?


Also for vectors you can just assign another vector by using the '=' assignment operator. If you want the reverse it, then use the std::reverse to reverse a vector then use the assignment operator, better practice.

mrnutty 761 Senior Poster

Do you have the exact wording of the problem? You cannot turn an unordered list into an ordered one without sorting it.

Yep, not unless you obscure the meaning of "sorting".

mrnutty 761 Senior Poster

Take spanish. Its more popular so you can make more contacts.

mrnutty 761 Senior Poster

Do something like this, in psuedo code

initAllVariables
bool play = true;

while( play)
{
    //print board;
    //get user input
    //if input is invalid, try again
   // insert the input into the gameBoardArray
    // print board
   // while valid : generate computer move
  // print board
  //check if game is over
 // if over ask user to play again ?
 // if yes call resetFunction that resets everything.
 //else return 0;
}
mrnutty 761 Senior Poster

I use netbeans but was wondering if anyone knew how to add a Java compiler to visual studio 2008?

mrnutty 761 Senior Poster

do you need to know the size of the char array? If so then add it to the set* prototype.

mrnutty 761 Senior Poster

First define the showBoard. Maybe this will get you started :

void showBoard (char t[3][3])
{	
	for(int i = 0; i < 3; i++)
	{
		cout<<"---------------------\n";

		for(int j = 0; j < 3; j++)
		{
			cout << t[i][j] << "   |   ";
		}
		cout<<endl;
	}
	cout<<"---------------------\n";
}

Then after you get the position where the user wants to put a X or an 0, insert it into the 2d array and call the print
function again. This all should go until the game is over.