NathanOliver 429 Veteran Poster Featured Poster

The since you are using operator bool it will only be false when badbit and or failbit is set. The first time you close the file and evaluate operator bool none of those are set so the operator returns true. Calling close() on the stream a second time will fail since it is already closed and since the function fails the failbit is set. The next time you evaluate the stream using operator bool it returns false.

NathanOliver 429 Veteran Poster Featured Poster
NathanOliver 429 Veteran Poster Featured Poster

@basit_3 you need to convert the String^ to a std::string if you need want to use std::ofstream you con use this to convert the string(source: MSDN):

// convert_system_string.cpp
// compile with: /clr
#include <string>
#include <iostream>
using namespace std;
using namespace System;

void MarshalString ( String ^ s, string& os ) {
   using namespace Runtime::InteropServices;
   const char* chars = 
      (const char*)(Marshal::StringToHGlobalAnsi(s)).ToPointer();
   os = chars;
   Marshal::FreeHGlobal(IntPtr((void*)chars));
}

void MarshalString ( String ^ s, wstring& os ) {
   using namespace Runtime::InteropServices;
   const wchar_t* chars = 
      (const wchar_t*)(Marshal::StringToHGlobalUni(s)).ToPointer();
   os = chars;
   Marshal::FreeHGlobal(IntPtr((void*)chars));
}

int main() {
   string a = "test";
   wstring b = L"test2";
   String ^ c = gcnew String("abcd");

   cout << a << endl;
   MarshalString(c, a);
   c = "efgh";
   MarshalString(c, b);
   cout << a << endl;
   wcout << b << endl;
}
NathanOliver 429 Veteran Poster Featured Poster

Okay I'm done. That wasn't to hard.

NathanOliver 429 Veteran Poster Featured Poster

Now that we have C++11 there are two options when you want an array object and don't want to use a native array. If you want an array of a fixed size you should use a std::array. This has the benefit over native arrays where if you pass it to a function you no longer lose the size of the array as it doesn't decay into a pointer.

If you need dynamic memeory allocation(ie you don't know how many things you are going to need to store) then you want to use a std::vector. A vector can resize durring runtime and handles all of the memory managment for you.

NathanOliver 429 Veteran Poster Featured Poster

More than likely cygwin is using some command to compile and that command doesn't change and either needs to be changed by you or can't be changed causing this issue. Take a look at this SO post on compiling with cygwin: http://stackoverflow.com/questions/1753239/compile-c-with-cygwin

NathanOliver 429 Veteran Poster Featured Poster

You should never include a .cpp file in another file. .cpp files should include .h/.hpp files and then all of those .h/.hpp and the .cpp file get compiled together to make an object file. This should happen for each .cpp file you have in your project. Once that happens then all of those objects should be linked together by the linker to make the final executable.

NathanOliver 429 Veteran Poster Featured Poster

What no one helped you the first time so you are trying again? It's been 5 days and all you have come up with is "give me the code".

NathanOliver 429 Veteran Poster Featured Poster

The push_back() function of standard container appends to the end of the container the value passed to it. If the size() of the container equals the capacity() of the container then the container will grow to accommodate the new element.

NathanOliver 429 Veteran Poster Featured Poster

Don't use goto. In this case to get out of your nested loops just use return a*b*c; where you have goto End_of_Loop;. There is no point exiting out of the loops to get to the return statement when return will kill the function for you.

NathanOliver 429 Veteran Poster Featured Poster

@rubberman According to the standard 3.6.1.5 main has an implicit return 0; if one is not provided

A return statement in main has the effect of leaving the main function (destroying any objects with automatic storage duration) and calling std::exit with the return value as the argument. If control reaches the end of main without encountering a return statement, the effect is that of executing
return 0;

NathanOliver 429 Veteran Poster Featured Poster

Can you post the code that is giving you the warning? If you never use number2 then you should be able to just get rid of it.

NathanOliver 429 Veteran Poster Featured Poster

You are pushing back the number on line 19 in your second code block. Get rid of that and you should be fine.

cout<<"Enter a nonnegative integer:";
cin >> num;
stack1.push(num);
while(num>0)
//...

Becomes

cout<<"Enter a nonnegative integer:";
cin >> num;
while(num>0)
//...
NathanOliver 429 Veteran Poster Featured Poster

1) Open program to write code
2) Write code
3) Compile code
4) If you have compiler errors fix them and go to step 3 else continue
5) Run code and make sure you get what you want else go to step 2

NathanOliver 429 Veteran Poster Featured Poster

So what part is giving you a problem?

NathanOliver 429 Veteran Poster Featured Poster

Didnt like your downvote?

NathanOliver 429 Veteran Poster Featured Poster

Has anyone noticed that there seams to be a large number of new users that are just copy and pasting their homework requirements into their post and that's it? Do we have anything like SO that analyzes post to see if they might not meet the sites standards? Just from today on the 1st C++ page we have these post that are making no effort at all to try and solve their problems

https://www.daniweb.com/software-development/cpp/threads/493340/c-question-
https://www.daniweb.com/software-development/cpp/threads/493921/write-a-program-in-c-that-allows-the-user-to-enter-amount-in-dollars-and
https://www.daniweb.com/software-development/cpp/threads/493879/sub-directory
https://www.daniweb.com/software-development/cpp/threads/493862/problem-help-me

It just seams to me at least that we are getting a lot of garbage on the forum.

NathanOliver 429 Veteran Poster Featured Poster

I just want to point out that if part of the requirement is to not use any dynamic memory allocation you shouldn't be able to use a vector. A vector is just a wrapper for a dynamic array. I am being a little nit picky about that but your professor doesn't seam to care so vector FTW.

NathanOliver 429 Veteran Poster Featured Poster

You need to add them to the solution.

NathanOliver 429 Veteran Poster Featured Poster

You don't have any structs. Are you trying to sort parallel arrays?

NathanOliver 429 Veteran Poster Featured Poster

You are going to have to loop through your data and find the min and max frequency. Then you have to loop through your array and print out all of the numbers that have the same max frequency. Then you have to loop through your array and print out all of the numbers that have the same min frequency.

void FindMaxMin(int *x)
{
    int max = 0;
    int min = 9;

    for (int i = 0; i < 10; i++)
    {
        if (ALL[i].freq > max)
        {
            max = ALL[i].freq;                    
        }
        if(ALL[i].freq < min)
        {
            min = ALL[i].freq;
        }
    }
    for (int i = 0; i < 10; i++)
    {
        if (ALL[i].freq == max)
            cout << "Number(s) with the largest frequency of " << max << " is/are: " << x[i] << endl;
    }
    for (int i = 0; i < 10; i++)
    {
        if (ALL[i].freq == min)
            cout << "Number(s) with the lowest frequency of " << min << " is/are: " << x[i] << endl;
    }
}
NathanOliver 429 Veteran Poster Featured Poster

I took it as this was going to be about the answer to Life, The Universe and Everything.

NathanOliver 429 Veteran Poster Featured Poster

Repeating the same bad question isn't going to help you. Take a look at the rules and also see how to ask a good question

NathanOliver 429 Veteran Poster Featured Poster

To loop a whole program this is what I use:

char continue;
do
{
    // program code goes here
    std::cout << <<"Press 'Y' to repeat and 'N' tp exit\n";
    std::cin >> continue;
} while (::tolower(continue) != 'n');

This will continue the loop as long as an N or n is not entered.

NathanOliver 429 Veteran Poster Featured Poster

Did you try to google that?

NathanOliver 429 Veteran Poster Featured Poster

Is the podofo.lib file located in the directories you have listed?

NathanOliver 429 Veteran Poster Featured Poster

Please detail what the problem is, what you have tried to solve it and any errors you are getting with the code you have.

NathanOliver 429 Veteran Poster Featured Poster

Why dont you compile it and find out?

NathanOliver 429 Veteran Poster Featured Poster

This is why proper indention is so important.

NathanOliver 429 Veteran Poster Featured Poster

Does line 7:int func(int); look the same as line 22:int func(int base, int power)?

NathanOliver 429 Veteran Poster Featured Poster

Congratulations. C++ is a very complex and powerfull language. If you are looking for reference on how to learn C++ I would visit here

NathanOliver 429 Veteran Poster Featured Poster

Why dont you run it an find out?

NathanOliver 429 Veteran Poster Featured Poster

@serpi90 I think you are confusing how derived objects get created. If you have:

class A
{
    A() { /*do super complicated stuff in here to set up A*/ }
    virtual void Foo();
};

Class B : public A
{
    B() : A() { /*set up the B object here*/  }
    void Foo();
};

Class C : public A
{
    C() : A() { /*set up the C object here*/  }
    void Foo();
};

As you can see the derived object calls the base class constructor which handles constructing the base part of the derived object and then the B constructor takes care of setting the stuff up that belongs to B. The point of marking function virtual is so you can do this:

vector<A*> data;
data.push_back(new B());
data.push_back(new C());

for (auto& e : data)
    e->someFunc();

Here the right function gets called in the for loop. As you can see though we still have to construct the object with the right constructor.

NathanOliver 429 Veteran Poster Featured Poster

*(C + B) = A; = C[B] = A;
*(G + F + 1) = E; = G[f+1] = E;

NathanOliver 429 Veteran Poster Featured Poster

Why would you have a virtual constructor? The reason you use virtual is to create a virtual table so that when a function is called from a pointer to a base it will call the function of the derived object that was stored in that pointer. Since you have to explicitly call the constructor when you create an derived object there is no reason to have it virtual. The destructor needs to be virtual though since you are calling destroy on the base pointer and the program needs to know what derived object destructor to use.

NathanOliver 429 Veteran Poster Featured Poster

With the number of people posting just their homework maybe the instructors have noticed that and made the assignments easier to give us a break ;)

NathanOliver 429 Veteran Poster Featured Poster

And? Is there a problem or you just showing the final code? I do think while (MinutesOfWork > MinutesVisit); should be while (MinutesOfWork >= MinutesVisit);

NathanOliver 429 Veteran Poster Featured Poster

You should not be getting any input from the user. You need to figure out how many appointments the sales person can do per day. Once you know that then you know how many visits he can do in 2 weeks. Once you have that then you can multiply the 2 week total by 110% to find out the second 2 week amount. Add those two numbers together and now you have the total profit per month.

Most of programing is problem solving. Solve the problem manually and then translate those steps into code. using psuedocode is another way to help the transition from pen and paper to code.

ddanbe commented: extensive advise. +15
NathanOliver 429 Veteran Poster Featured Poster

Did you try to do this with pseudocode to see what the operations are? The folowing pseudocode should help you with how you need to write the program.

number age = 0,  max = 0;
string name, oldest
while(true)
    get name
    if name == "quit"
        break
    get age
    if age > max
        max = age
        oldest = name
end while
display << "the oldesy person is " << oldest
NathanOliver 429 Veteran Poster Featured Poster

This is not a code writing service. If you have code and it is giving you a problem then post the code and what the problem is. No one here is going to do your work for you.

NathanOliver 429 Veteran Poster Featured Poster

This is not a code writing service. If you have code and it is giving you a problem then post the code and what the problem is. No one here is going to do your work for you.

rubberman commented: :-) +13
NathanOliver 429 Veteran Poster Featured Poster

Can you post the code you have now? It's hard to read your screen from here.

NathanOliver 429 Veteran Poster Featured Poster

I'm pretty sure this was given to you to answer.

NathanOliver 429 Veteran Poster Featured Poster

When doing operations like this you should look at using the copy and swap idiom.

NathanOliver 429 Veteran Poster Featured Poster

I would think and decent compiler would make even % 2 and even & 1 the same operation. My rule of thumb is write clear and legible code. This will help with maintainability and will generally allow the optimizer to take care of most optimizations that can been done. mike_2000_17 wrote a very nice guide showing how you can really get a nice performance increase in your code without using any sort of micro optimizations.

NathanOliver 429 Veteran Poster Featured Poster

@rubberman Microsoft does offer an express version of MS SQL Server that is free. I am looking at that right now for some time and attendance software that needs a DB for the backend. You can check it out here.

rubberman commented: I knew, but forgot about that. Thanks. +13
NathanOliver 429 Veteran Poster Featured Poster

Now if he offered to pay for this that would be a different story. I don't know about the rest of you but I think if the OP offered $1000 USD per hour at a minimum of 8 hours we would be more inclined to help.

NathanOliver 429 Veteran Poster Featured Poster

Please don't resurrect dead threads that have already been answered.

NathanOliver 429 Veteran Poster Featured Poster

Just another person hoping that the internet is the answer to all of lives problems.

triumphost commented: Lol. I like this quote. Stealing it! +8
NathanOliver 429 Veteran Poster Featured Poster

If our output should be:

Popping...a
Popping...b
Popping...c
Popping...d
Popping...e
Popping...f

Then you need to be storing a,b,c,d,e and f in your stack. right now you are storing 1,2,3,4 and 5 with char a='1',b='2',c='3',d='4',e='5',f='6';. You can change it to char a='a',b='b',c='c',d='d',e='e',f='f'; to get the desired output. The stack is only going to give you what you put into it.

As a side note cout<<mystack1.pop(char)<<endl; makes no sense and should give you a compiler error. If you are trying to cast to a char then you and use cout<<(char)mystack1.pop()<<endl; or since this is C++ `cout<<static_cast<char>(mystack1.pop())<<endl;

TObannion commented: That's what I was looking for. As for "f", it's just an extra value to demonstrate when the stack is full. Thanks so much! +0