NathanOliver 429 Veteran Poster Featured Poster

By default members of a class are private not public. If you want to make them public you need to use the public keyword.

class foo
{
    int bar;
public:
    foo() : bar(10) {}
    int getBar() const {return bar; }
}

int main
{
    foo temp;
    int testBar;
    testBar = temp.bar; // error bar is private
    testBar = temp.getBar();  // okay getBar() is public
}
NathanOliver 429 Veteran Poster Featured Poster

If you want to find the size of a char array and you dont want to use the strlen() function in the cstring header then you can use this.

//...
char sentence[80];
cout << "Enter a sentence to find the length: ";
cin.getline(sentence, 80);
int stringSize = 0;
while(sentence[stringSize] != '\0')
{
    stringSize++;
}
//...

You can make it shorter but that will give you the jist of it.

NathanOliver 429 Veteran Poster Featured Poster

What happenes if you do

return to_bin(static_cast<unsigned int>(dec), size);

on line 36?

NathanOliver 429 Veteran Poster Featured Poster

Well if you have a array of 100000 doubles it would only need about 8mb of ram so I'm not sure why you wouldn't be able to create an array of 10000 elements unless they use a lot of memory. What is the error that you are getting and what compiler/IDE are you using?

NathanOliver 429 Veteran Poster Featured Poster

It is all dependent on the amount of ram int the system. Are you creating the array using the new operator or are you defining the size at compile time?

NathanOliver 429 Veteran Poster Featured Poster

An array's size is only limited to the memory of the machine running the code. If you want to make an array larger you will need to read up on dynamic arrays. If you need storage that can get very large or you need it to grow I would suggest using something from the STL. Perhaps a vector would work for you.

NathanOliver 429 Veteran Poster Featured Poster

Well you can do like the standard library does and say that a iterator a pointer to the data of a class is only good until the next time you use the object.

NathanOliver 429 Veteran Poster Featured Poster

Try checking out the <windows.h> functions

NathanOliver 429 Veteran Poster Featured Poster

If you want to find the second max you need to have 2 max variables. the first will hold the actual max and the second will hold the number that is greatest after that.

int max = 0, max2 = 0, grade;
cout << "Please enter your numbers (-1 to quit): ";
while (cin >> grade)  // loop for input
{
    if (grade == -1)  // ends input
        break
    if (grade > max)  // check for maximum value
        max = grade;
    if (grade > max2 && max != grade) // only do this if grade isn't max
        max2 = grade;
}
ryrtyu commented: not hold second no .it shows zero +0
NathanOliver 429 Veteran Poster Featured Poster

line 2 in your in the cpp file should be

fraction fraction::addFractions(fraction two)

The reason it was not working they way you had it was because you did not have the return type in the deceleration.

NathanOliver 429 Veteran Poster Featured Poster

The problem is you defined you function as using ofstream and ifstream. These are the objects used for handling files. If you want to use you class with cin and cout you need to use istream and ostream.

NathanOliver 429 Veteran Poster Featured Poster

To pass a vector by reference to a function like your add function you can do this.

//prototype
vector<int> & AddElement(vector<int> & container, int foo);

// definition
vector<int> & AddElement(vector<int> & container, int foo)
{
    container.push_back(foo);
    return container;
}
NathanOliver 429 Veteran Poster Featured Poster

You don't need to install Linux. You can install code::blocks and then link it to a gcc compiler. Check this out.

NathanOliver 429 Veteran Poster Featured Poster

Look at this

// defenition
int getNumAccidents(string)
// decleration
int getNumAccident(string name)

(hint) See how the ( don't line up.

NathanOliver 429 Veteran Poster Featured Poster

I think what you are looking for is a 2d vector. If that is what you are trying to do than to declare a 2d vector use

std::vector<std::vector<string> > rows;
NathanOliver 429 Veteran Poster Featured Poster

Ell you can only return one variable. If you want to return information from your function to more than 1 variable you will need to pass the variable into the function by reference or a pointer. That said I think a reference will be fine for you. See how this works.

int foo(int regionSelect, string & region)
{
    switch(regionSelect)
    {
        case 1: region = "North";
    }
    return someNumber;
}
NathanOliver 429 Veteran Poster Featured Poster

well you need an ofstream object opened to the file that you want. after you do that in for loop output the char array to the file using the >> operator.

NathanOliver 429 Veteran Poster Featured Poster

line 52 should be Stack g; . The reason for this is the compiler is interpreting line 52 as a function that returns a Stack and takes no arguments.

NathanOliver 429 Veteran Poster Featured Poster

If you can use STL then you could use the random shuffle algo. Since I don't think you can use that algo you would need to use two for loops. One to populate the array with the numbers 1-20 and the other to swap the elements in the array around. When you shuffle the element around go through the array for each element swap it with a random index in the array.

NathanOliver 429 Veteran Poster Featured Poster

please post the code you are using right now

NathanOliver 429 Veteran Poster Featured Poster

the reason he has it returning the an istream reference is to be able to chain it. by that I mean

cin >> input >> anotherInput >> read_hw(cin, homework);
NathanOliver 429 Veteran Poster Featured Poster

the part that says run error code is for you to complete. You need to put the code there to handle an invalid object.

NathanOliver 429 Veteran Poster Featured Poster

Are you supposed to implement your own list class?

NathanOliver 429 Veteran Poster Featured Poster

To follow WaltP's adive you could simply do

srand(unsigned(time(0)));
string names[] = {"Jim", "Tom", "Jeff", "Larry"};
cout << "The person that should drive is: " << names[rand % 4] << ".";
NathanOliver 429 Veteran Poster Featured Poster

You might be able to do something like this.

//...
      if((strcmp(token[0], "PRISM") == 0))
      {
        if((prismSide1 = atof(token[1]) = 0.0);
            run error code
        if((prismSide2 = atof(token[2]) = 0.0);
            run error code
        if((prismSide3 = atof(token[3]) = 0.0);
            run error code
        prismCalc(prismSide1, prismSide2, prismSide3);
      } //if
//...

Personally I would use string streams for the conversion and then check if the stringstream failed or not.

NathanOliver 429 Veteran Poster Featured Poster

The second is invalid. Only a pointer to can use the new operator. Here is a little breakdown for you.

int foo = 10;  // normal assignment;
int *fooPointer = new int;
*fooPointer = foo;  // now fooPointer is a pointer to an int that holds the value of 10
int & fooReference = foo;  // reference.  now anything that happens to fooReference happens to foo.
NathanOliver 429 Veteran Poster Featured Poster

There was a bug in the code that I posted. you need to move line 46 in your code to be in between lines 48 and 49. Your isPrime function also needs some work. You have 9 in your prime pairs and 9 is not a prime number. Here is a isPrime function for you to digest

bool isPrime(int number)
{
    if (number == 1 || number == 2)
		return true;
    for (int i = 3; i * i <= number; i+=2)  // only check odd numbers and limit checks to sqrt(number) using * instead of sqrt()
    {
	if (number % i == 0)
		return false;
    }
    return true;
}
NathanOliver 429 Veteran Poster Featured Poster

The way I would go about this is to use a prime number function. Then use a while loop to keep track of how many sets of primes you have found

bool isPrime(int number)
{
    // put code here to check if a number is prime;
}

int main()
{
    int numberOfSets;
    int SetsFound = 0;
    int primeNumber = 3;
    cout << "How many twins do you want to find: ";
    cin >> numberOfSets;
    while (setsFound < numberOfSets)
    {
        if (isPrime(primeNumber) && isPrime(primeNumber + 2))
        {
            cout << "(" << primeNumber << ", " << primeNumber + 2 << ")\n";
            primNumber += 2
            setsFound++;
        }
    }
    return 0;
}

The font gets converted to how the bbcode is set up. I don't believe there is a way to change that.

NathanOliver 429 Veteran Poster Featured Poster

I would have to agree with caut_baia that we need to see find_original and also some more of your code.

NathanOliver 429 Veteran Poster Featured Poster

Why are you including a .cpp file? The general structure of the the files should be like

main.cpp: This is the cpp file where main is. You can call it anything. In this file you will include all header files needed

className.h: This is where the declaration of the class goes

className.cpp: This is where you define your class.

//main.cpp
#include <iostream>
#inlcude "Player.h"
#inlcude "Game.h"

int main()
{
    //...
}
//  player.h
class Player
{
   // just the declaration
};

// player.cpp
Player::Player()
{
    //...
}

Player Player::GetName() const { return name; }

//...
// game.h
class Game
{
    // just the declaration
};

// game.cpp
Game::Game()
{
    //...
}

Player Game::GetPlayer(int index) const { return Players[index]; }
NathanOliver 429 Veteran Poster Featured Poster

Sorry The code should look like this

std::vector<team> GetTeamInfo()
{
    int numTeams = 0;
    std::cout << "Please enter the number of teams: ";
    std::cin >> numTeams;
    std::vector<team> teams(numTeams);
    for (int i = 0; i < numTeams; i++)
    {
        std::cout << "please enter the name of team "<<(t)<<endl;
	std::cin >> teams[i].name;
	std::cout << "please enter the attack score of "<<name<<" (0 - 100) " << endl;
	std::cin >> teams[i].atk;
	std::cout << "please enter the defence score of "<<name<<" (0 - 100) " << endl;
	std::cin >> teams[i].def;
	std::cout << "please enter the keeper skill score for "<<name<<" (0 - 100) " << endl;
	std::cin >> teams[i].keeper;
	std::cout << "please enter the striker skill score for "<<name<<" (0 - 100) " << endl;
	std::cin >> teams[i].striker;
    }
}
NathanOliver 429 Veteran Poster Featured Poster

On line 29 you are declaring structs for each variable.

void setup (struct team one, struct team two, struct team three, struct team four, struct team five, struct team six, struct team seven, struct team eight)

It should be

void setup (team one, team two, team three, team four, team five, team six, team seven, team eight)

Also if you want your structs to retain what happens to them in the functions then you need to pass them by reference.

void game(team & one, team & two);

You also might want to look up vectors. using vectors and loops would significantly cut back on the code you are writing. As an example here is how you could write an input method.

void GetTeamInfo(std::vector<team> & teams)
{
    int numTeams = 0;
    std::cout << "Please enter the number of teams: ";
    std::cin >> numTeams;
    for (int i = 0; i < numTeams; i++)
    {
        std::cout << "please enter the name of team "<<(t)<<endl;
	std::cin >> teams[i].name;
	std::cout << "please enter the attack score of "<<name<<" (0 - 100) " << endl;
	std::cin >> teams[i].atk;
	std::cout << "please enter the defence score of "<<name<<" (0 - 100) " << endl;
	std::cin >> teams[i].def;
	std::cout << "please enter the keeper skill score for "<<name<<" (0 - 100) " << endl;
	std::cin >> teams[i].keeper;
	std::cout << "please enter the striker skill score for "<<name<<" (0 - 100) " << endl;
	std::cin >> teams[i].striker;
    }
}
NathanOliver 429 Veteran Poster Featured Poster

Depending on your knowledge you can do a couple things. You could read the entire line into a string and then use a stringstream to parse it. you could put the other 7 variables in a vector or some other sort of container. If you want all 7 in the same string then after you read in the first 3 variables then just use getline and read the rest into the fourth variable.

NathanOliver 429 Veteran Poster Featured Poster

Well if you are only using positive numbers you can use setfill() and right() to get padded zeros. if you are going to have negative numbers then I think some string manipulation will be in order.

setfill -> http://www.cplusplus.com/reference/iostream/manipulators/setfill/

right -> http://www.cplusplus.com/reference/iostream/manipulators/right/

NathanOliver 429 Veteran Poster Featured Poster

I had asked why you included <stream>. You should include <string> in your code.

NathanOliver 429 Veteran Poster Featured Poster

How is the file formatted? What type of data is in the file?

NathanOliver 429 Veteran Poster Featured Poster

You can use setpercision() to do this. Here has some good examples.

NathanOliver 429 Veteran Poster Featured Poster

cout << "Welcome to the gradebook for\n" ; getCourseName() there is a semicolon when there should be a <<. As far as i know there is not a <stream> header file. Why are you including it?

NathanOliver 429 Veteran Poster Featured Poster

Please post your code.

NathanOliver 429 Veteran Poster Featured Poster

Yes Beacuse when you pass by reference you dont need to copy the entire vector like you do when you pass it by value. if you had a vector of 1000 objects each 10 bytes in size then to pass it by value you would have to copy all 10kb worth of data. passing by reference you copy 10 bytes.

NathanOliver 429 Veteran Poster Featured Poster

Line 9 in narueReader should not be there. you never want to include the std namespace into your own namspace. Same goes for writer where you include std and the matrix namespace. you should fully qualify anything used from a seperate namespace in another namespace.

// this can cause problems
namespace foo
{
    using namespace std;   // very bad
    void Print(bar & temp)
    {
        cout << temp;
    }
    //...
}

// this one is fine
namespace foo
{
    void Print(bar & temp)
    {
        std::cout << temp;
    }
    //...
}
NathanOliver 429 Veteran Poster Featured Poster

Sorry I meant to say reinstall. I typed that on my phone and auto complete took over. It appears that everything is related to MSVCRT.lib. I would check to make sure the file exist and is where it is supposed to be. You might also want to check that you are not trying to link to the static and dynamic lib's at the same time.

NathanOliver 429 Veteran Poster Featured Poster

Have you tried really installing msvc++?

NathanOliver 429 Veteran Poster Featured Poster

Can you plaese post the relevant code.

NathanOliver 429 Veteran Poster Featured Poster

Also if you create a constructor for your class don't forget to also provide a default constructor. A default constructor is only provided if there are no constructors defined.

NathanOliver 429 Veteran Poster Featured Poster

The value of ' ' is not 0. In fact, I challenge you to input a character with the value of 0 using cin. It's not as simple as you might think.

I believe this means she is asking you to input a null into the input stream.

NathanOliver 429 Veteran Poster Featured Poster

Well the ASCII character code says that 0 = NULL so I would think that you cant exactly enter a NULL character. this is a reference that I use from time to time.

NathanOliver 429 Veteran Poster Featured Poster

A char that has an integer equivalent of 0 is an undefined character on output isn't it?

NathanOliver 429 Veteran Poster Featured Poster

Thank you very much Narue

NathanOliver 429 Veteran Poster Featured Poster

Thanks Narue for your answer. I wasn't sure if you could declare a function inside a function. Does that change the scope of that function to where it can only be used in the function it is declared in?