NathanOliver 429 Veteran Poster Featured Poster

No you can not overload ::. Why would you want to?

NathanOliver 429 Veteran Poster Featured Poster

So why do you want characters?

NathanOliver 429 Veteran Poster Featured Poster

So what do you need? Can you assume what a college student is and what you need to have for members and functions?

NathanOliver 429 Veteran Poster Featured Poster

Why are you looking for spaces in a csv file? csv stands for comma seperated values. Your file should look like

1.1,1.2,1.3
2.1,2.2,2.3
...
NathanOliver 429 Veteran Poster Featured Poster

Did you check to see if prices had anything in it? What happenes if you put this after line 17 and before line 18?

if(prices.size() < 2)
    cout << "Vector size less than 2!" << endl
else
    cout << "Vector has 2 or more elements!" << endl
NathanOliver 429 Veteran Poster Featured Poster

A should actually look like this

if (x == 0) then     //constant (1)
  for i = 1 to n do // linear(n)
       a[i] = i; //constant (1)

Resenje:
T(n) = O(1) + O(n) * O(1) = O(n)

B should look like this

i = 1; //constant (1)
repeat
    a[i] = b[i] + c[i]; //constant (1)
    i = i +1;  //constant (1)
until (i == n); // linear(n)

T(n) = O(1) + O(1) * O(n) = O(n)
NathanOliver 429 Veteran Poster Featured Poster

Yes what you came up with is correct. If you want to write it in big-O notation it would be O(n).

NathanOliver 429 Veteran Poster Featured Poster

I would think they are just looking for big O notation since they give no size for n.

NathanOliver 429 Veteran Poster Featured Poster

you need to move the while loop outside of your for loop

void Concatenation( char dest[MAX_S_ROWS][MAX_S_COLS] ) // max_s_row = 208
{                                                       // max_s_cols = 25;
    for(int i=0, j = 0; i<200; i+=2, ++j)
    {
        myStrCat2(dest[j], dest[i],dest[i+1]);
    }
    while( j < MAX_S_ROWS ) // this loop is making the program close
    {
        dest[j++][0] = 0;
    }
}
NathanOliver 429 Veteran Poster Featured Poster

You could write your display like this

for (int i = 0; destination[i][0] != '\0'; i++)
    cout << destination[i] << " ";
NathanOliver 429 Veteran Poster Featured Poster

Don't forget that you will need to add the counter increment to the copy constructor and the assignment operator. You probobly want to have that as a seperate counter since those objects will be implicitly created.

NathanOliver 429 Veteran Poster Featured Poster

I know microsoft uses -1 as true if you are using access so it makes sense that they are doing that with there compiler. AFIK any value other than 0 is considered true and I havent seen a case where that doesnt work.

NathanOliver 429 Veteran Poster Featured Poster

The code in your first piece of code should not compile. More than likely there is some sort of compiler extension taking care of it for you. What compiler are you using? Static arrays can only be initialized with a const size argument.

NathanOliver 429 Veteran Poster Featured Poster

a const function can be called by a non const function. a const function can only call other const functions. the same thing applies to objects as well.

NathanOliver 429 Veteran Poster Featured Poster

what compiler are you using? if you are using msvc++ you have to pick a win32 console application.

NathanOliver 429 Veteran Poster Featured Poster

can you post the code?

NathanOliver 429 Veteran Poster Featured Poster

You can use the same method. Instead of using cin you would use the file stream you create.

ifstream fin("testfile.txt");  //create ifstream object to read the file
string line;
vector<string> fileContents;

while(getline(fin, line))
    fileContents.push_back(line);

As you can see from the above example fin is the file stream to read from the file. fileContents is a vector that will store each line of the file. The while loop uses the return value from getline to know if a line was read from the file. If the getline operation fails the loop stops and nothing more is read from the file. Inside the while loop the contents of the variable line are then added to the back of the vector.

If you want a good reference site I would suggest visiting cplusplus.com. They have a lot of tutorials and references. And of course if you have problems come back here and someone should be able to help.

furalise commented: Excellent answer. Thanks for the help. +0
NathanOliver 429 Veteran Poster Featured Poster

What do you mean by getting the sentence from somewhere else? Do you mean like getting it from a file or passing the variable to the program using the command line? If you put the sentence in a variable you can use it in your progrma anywhere you want to as long as that variable is visable to the code block you are in.

NathanOliver 429 Veteran Poster Featured Poster

Well if you want to store the sentance in a variable use a string not a stringstream. Your code would look like this

string line;
getline(cin, line); // gets the sentence from the command line and place it in line
cout << "You Entered: " << line << endl;
NathanOliver 429 Veteran Poster Featured Poster

@ sanyam.mishra char* argv[FILENAME_MAX] is an array of pointers so it is a 2d array.

@ DarrelMan have you walked through the code with the debugger to see what is inside argv[0]? If you dont know how to step through the code with the debuger you could just output the contents of argv[0] to the console using a cout statement. That should at leat tell you what you have. it could be there is a slight mismatch.

NathanOliver 429 Veteran Poster Featured Poster

add this after line 14 to see if your file is being opened.

if(!myfile)
    std::cout << "Unable to open file" << std::endl;
NathanOliver 429 Veteran Poster Featured Poster

program does not work:

Can you alaborate a little more than that?

Your fist for loop needs to have its statements wrapped in brackets since there are multiple lines.

for(int i = 0; i < 7; i++)
{
    //code here
    //code here
}

You are never multiplying the total by the difficulty.

NathanOliver 429 Veteran Poster Featured Poster

Want to post the code you have?

NathanOliver 429 Veteran Poster Featured Poster

What all is in word? is it just one word or a sentence. I ask because I dont know of a word that is 40 letters long outside of chemical compounds. How do you want to split the word? If the word puts you over 40 charecters do you split it or do you put the whole word on a new line.

NathanOliver 429 Veteran Poster Featured Poster

line 49 needs to be:

temp = temp + (data[i] * x.data[i]);

If you are mulitplying each vector element agianst the other. One issue I see is how are you going to handle mismatched vector sizes?

NathanOliver 429 Veteran Poster Featured Poster

stoi() is overloaded to take a string or a wstring.

NathanOliver 429 Veteran Poster Featured Poster

Use this as an example:
base class

//base.h
#ifndef BASE_H
#define BASE_H

class Base
{
    int foo;

public:
    Base(int number) : foo(number) {}
};

#endif

derived class

//derived.h
#ifndef DERIVED_H  //<- inclusion gaurding
#define DERIVED_H

#include "base.h"  //<- this adds the code from base.h to derived.h

class Derived : public Base
{
    int foobar;
public:
    Derived(int num1, int num2) : Base(num1), foobar(num2) {}
};

#endif

This is how your headers would look. Then in the .cpp files you would just need to include the .h that the .cpp file is named after.

base class .cpp file

//base.cpp
#include "base.h"

// all the code for the base class would go here

derived class .cpp file

//derived.cpp
#include "derived.cpp"

// all the code for the derived class would go here.
NathanOliver 429 Veteran Poster Featured Poster

You dont have to have it in your .h file for your derived class but you do need to included it in you .h file.

NathanOliver 429 Veteran Poster Featured Poster

No. You need to create a stack that uses a linked list for its data structure. You also need to indent you code correctly. If you look at the first post in your linked list thread the way the code is formatted there is how you should format your code when you post. I personally won’t read code that has no indentation.

NathanOliver 429 Veteran Poster Featured Poster

No. It says you have to implement this with a linked list.

NathanOliver 429 Veteran Poster Featured Poster

What is the code that you have? You need to search through the array and find a row that has enough open seats that are together.

NathanOliver 429 Veteran Poster Featured Poster

Check out the win32 API.

NathanOliver 429 Veteran Poster Featured Poster

Line 9 of you code is

double rightTriangle(double x, double y)

Line 25 of your code is

double rightTrangle(double x, double y)

Notice anything different? I'll give you a hint. Look at the name of the function.

NathanOliver 429 Veteran Poster Featured Poster

Line 24 needs to be nodeType* head_ptr;. That should fix some of the errors.

NathanOliver 429 Veteran Poster Featured Poster

Can you post the code that is giving you the problem? It is hard to read your screen from here.

NathanOliver 429 Veteran Poster Featured Poster

I wouldnt install a compiler that is over 15 years old on my machine. That is why we are being critical about your code. We should be able to compile it on any compiler that is at least complient with c++98.

NathanOliver 429 Veteran Poster Featured Poster

They really need to ban those compilers. I mean there is no <conio> header. Everything in the standard headers are in the std namespace which I dont see you using. main() returns and int and you dont even have the return type specified. global variables are a big no no. There is no reason in your code that the variables couldnt be defined inside main.

NathanOliver 429 Veteran Poster Featured Poster

Thanks deceptikon. Brilliant example.

NathanOliver 429 Veteran Poster Featured Poster

I Didn't know they had strtol(). I can still see cases where you have to validate the string though. If someone enters 'a' and you convert it to base 10 strtol() will return 0 since the conversion failed but you dont know if the conversion failed or if the user entered 0.

NathanOliver 429 Veteran Poster Featured Poster

Well if you cant use a stringstream you could always stor the line in a string and then manually parse the string yourself. The atoi() function will convert a char* into the int that it represents. To get the char* you can use substr() to get the number you want and then use c_str() on the sub string to get the char*.

ankit.4aug commented: thanks a lot +1
NathanOliver 429 Veteran Poster Featured Poster

This is how I would format your code.

void b_Physics::Collision(const s_Polygon& Obstruct)
{
    float Ntime = 0.0f;

    s_Polygon Polygon = this->Object.Polygon;

    switch(this->Object.Motion.HorizDir)
    {
        case s_Motion::LEFT: 
            Polygon.MinX = Polygon.MinX + this->Object.Motion.Xvel; 
            break;
        case s_Motion::RIGHT: 
            Polygon.MaxX = Polygon.MaxX + this->Object.Motion.Xvel; 
            break;
        default : break;
    }

    if(this->Object.Polygon.MinY < Obstruct.MaxY && this->Object.Polygon.MaxY > Obstruct.MinY)
    {
        if(this->Object.Motion.HorizDir == s_Motion::LEFT && Polygon.MinX < Obstruct.MaxX)
        {
            Ntime = this->Object.Polygon.MinX - Obstruct.MaxX / this->Object.Motion.Xvel;
            this->Object.Motion.Xvel = Obstruct.MaxX - this->Object.Polygon.MinX / Ntime;

        }
        else if(this->Object.Motion.HorizDir == s_Motion::RIGHT && Polygon.MaxX > Obstruct.MinX)
        {
            Ntime = Obstruct.MinX - this->Object.Polygon.MaxX / this->Object.Motion.Xvel;
            this->Object.Motion.Xvel = Obstruct.MinX - this->Object.Polygon.MaxX / Ntime;
        }
    }

    switch(this->Object.Motion.VerticDir)
    {
        case s_Motion::UP:
            Polygon.MinY = Polygon.MinY + this->Object.Motion.Yvel; 
            break;
        case s_Motion::DOWN: 
            Polygon.MaxY = Polygon.MaxY + this->Object.Motion.Yvel; 
            break;
        default : break;
    }

    if(this->Object.Polygon.MinX < Obstruct.MaxX && this->Object.Polygon.MaxX > Obstruct.MinX)
    {
        if(this->Object.Motion.VerticDir == s_Motion::UP && Polygon.MinY < Obstruct.MaxY)
        {
            Ntime = this->Object.Polygon.MinY - Obstruct.MaxY / this->Object.Motion.Yvel;
            this->Object.Motion.Yvel = Obstruct.MaxY - this->Object.Polygon.MinY / Ntime;

        }
        else if(this->Object.Motion.VerticDir == s_Motion::DOWN && Polygon.MaxY > Obstruct.MinY)
        {
            Ntime = Obstruct.MinY - this->Object.Polygon.MaxY / this->Object.Motion.Yvel;
            this->Object.Motion.Yvel = Obstruct.MaxY - this->Object.Polygon.MinY / Ntime;
        }
    }
}
NathanOliver 429 Veteran Poster Featured Poster

trantran I just wanted to let you know that I use xrdp in linux in order to RDP into the machine. As for the problems you are experiancing I would have to try it on my own machine later but i can say i have never had a problem with this.

I also wanted to let you know that if you think that something that is open source and changing daily is a stable platform then you might need to rethink what you are using. Look at all of the SP's and patches microsft has to come up with and they are a multi billion dollar company. I have a server here at work that is linux and we are running VMWare on it for our virtual infrastructure. We last shut downt that server in october 2010. I would say that having an entier company running for 2+ year of solid uptime is pretty stable.

NathanOliver 429 Veteran Poster Featured Poster

@ vmanes Shouldnt line 10 of your snippet be

dest[index] = '\0';  // null terminate the destination string
NathanOliver 429 Veteran Poster Featured Poster

correct me if I am wrong and since I dont have my compiler in front of me I might be. If you have c = a * b, then can't you just do a check after the mulitplication for c / a == b? If c overflows it should break. The only case I can see in my head is if either a or b equals the maximum for the data type.

NathanOliver 429 Veteran Poster Featured Poster

1) It is just the way I like to do it. It really doesnt make a difference. I have dual monitors so it makes the second monitor look more like it is its own computer. Like I said it's just my preference.

2) My host OS is windows 7 pro 64bit.

3) I have not used another OS for the host machine.

NathanOliver 429 Veteran Poster Featured Poster

The reason I use VMWare Player is that we use VMWare at work so I am more comfortable. When I said that I RDP into the virtual machine that means I do a remote desktop into the machine so it like I am just remotely accessing the machine instead of being in the player. I'm not sure what kind of challenges you have been facing but I haven’t had any issues starting a new virtual machine from an iso file to create the OS. I do have an i5 processor with 16GB of ram in my machine so I can run my main OS plus 2 virtual machines at the same time and have a pretty seamless experience.

With VMWare player all I do is tell the software what specs for the virtual machine I want and then the location of the iso file that has the OS installation on it. I tell it to create at and the player opens up a screen to the new machine. It will read from the iso file and install it just like if you put the disk into a brand new machine. After the OS installs it is good to go.

NathanOliver 429 Veteran Poster Featured Poster

I am running Windows 7 and if I need another OS I use VMWare player to run the different OS. Once it is running I normally RDP into it for a cleaner look and feel

NathanOliver 429 Veteran Poster Featured Poster

Do you know if the char array is null terminated? If that is all the instructions say then based on what you posted I would say it is impossible. If the char array is null terminated then when you are going through the array your stop condition will be if where you are at is equal to '\0'

//...
int i = 0;
while(charArray[i++] != '\0')
{
    // check goes here
}
//...
NathanOliver 429 Veteran Poster Featured Poster

I think he copied the return statement and forgot to remove the semicolon after changing it to an if. Not sure why he would do that but hey.

NathanOliver 429 Veteran Poster Featured Poster

I would guess that the char array he is getting is a string and it is null terminated as well but that is just a guess. Without seeing the problem statement it's impossible to tell what is going on. Just like getting the size of an array from only a pointer to the begining ;)