NathanOliver 429 Veteran Poster Featured Poster

You can learn all about this problem here

NathanOliver 429 Veteran Poster Featured Poster

line 32 should be int IteratorTablou(int *crt = 0): crt(_crt)

You should also be returning a value from the function since you have an int return type. If you don't want to have a return then make the function void.

NathanOliver 429 Veteran Poster Featured Poster

Is your student class also a linked list?

senait.kifle.127 commented: Yes it is. +0
NathanOliver 429 Veteran Poster Featured Poster

Checking if the number is divisible by 3 or 5 can be switched around. The main thing is that you need to have the check for if it is divisible by 3 and 5 first otherwise the checks for 3 or 5 will trigger.

NathanOliver 429 Veteran Poster Featured Poster

I would think line 8 needs to be:

TableMenuShortCuts[TableMenuShortCuts.size()-1].key=(c[c.size()-1])[0];
cambalinho commented: thanks +3
NathanOliver 429 Veteran Poster Featured Poster

What did you plug in for the missing values and what does your for loop look like now? Remember when you are doing the summation that if the number is divisible by 15 you add 15, if it is divisible by 5 you add 5, if it is divisible by 3 then you add 3, otherwise you add only 1. when I run my version of the program for 5 to 15 I get 39.

NathanOliver 429 Veteran Poster Featured Poster

@cambalinho The reason you are gettting that error is std::string.c_str() returns a char* to the c-string the string contains. A char and a char* are not the same thing. If you want just the first character from the c-string then you can use:

TableMenuShortCuts[TableMenuShortCuts.size()-1].key=(j.c_str())[0];

// or

TableMenuShortCuts[TableMenuShortCuts.size()-1].key=*(j.c_str());
cambalinho commented: thanks +0
NathanOliver 429 Veteran Poster Featured Poster

Do you have graphics.h on your system? From what I remember graphics.h is a very old deprecated header from the good old DOS days. I wouldn't think it would be in GCC 4.x.

NathanOliver 429 Veteran Poster Featured Poster

Is it working now? Also you shouldn't be changing the value of i. i should only be used for controlling the loop. You are adding 1,3,5 or 15 depending on what i is divisible by. The code should look like this:

if (i%3==0 && i%5==0)
    sum += ;
else if (i%3==0) 
    sum += ;
else if (i%5==0)
    sum += ;
else 
    sum += ;
NathanOliver 429 Veteran Poster Featured Poster
x<=i<=y

Is not valid c++. If you need to loop between all number in x and y then you can use:

for (int i = x; i <= y; i++)

Wich is translated to: start with i equall to x and loop while i is less than or equall to y increment i by one with every iteration.

NathanOliver 429 Veteran Poster Featured Poster

The comments in your code tell you what you should do in each function. Try to code it out and if you prolems with the code then post it and we should be able to help.

Programming == Problem Solving
NathanOliver 429 Veteran Poster Featured Poster

What is giving you the problem? We are not here to do your homework for you.

NathanOliver 429 Veteran Poster Featured Poster

I like to use the website: http://www.cplusplus.com/reference/

NathanOliver 429 Veteran Poster Featured Poster

If this is code that you are submitting for people to see/use than I have a couple pointer for you. First this should have been posted as a code snippet. Secondly you should make sure you code is formated/indented properly. Here a couple examples for you. Personally I prefer the first method.

line of code;
more code;
if(something)
{
    more code;
    even more code;
    if(another condition)
    {
        even more code here;
    }
    some more code here;
}
last line of code;

// or 

line of code;
more code;
if(something){
    more code;
    even more code;
    if(another condition){
        even more code here;
    }
    some more code here;
}
last line of code;

Lastly your code should use meaningful varaible names. It is not readlily appernt based on your variables names what the variables hold. You shouldn't have to understand the code to know what the variables are. Making code maintanible is very important as it helps to find bugs and it allows other people to work on it.

NathanOliver 429 Veteran Poster Featured Poster

What need to know is how things are passed by reference or passed by value

NathanOliver 429 Veteran Poster Featured Poster

when something is evenly divisible by a number the modulo is 0.

15 / 3 = 5
15 % 3 = 0

Knowing this you can write the following code to see if something is divisble by a number:

if(someNUmber % 3 == 0)
    the number is divisble by 3
if(someNumber % 5 == 0)
    the number is divisble by 3
if(someNumber % 3 == 0 && someNumber % 5 == 0)
    the number is divisble by 3 and 5
NathanOliver 429 Veteran Poster Featured Poster

Since this is posted in the C++ forum how about:

std::cout << "*\n***\n*****\n*******\n*********\n*********\n*******\n*****\n***\n*";
NathanOliver 429 Veteran Poster Featured Poster

You can change your function to the following to take into account the filename.

bool operator() (finfo i, finfo j)
{
    if(i.fsize == j.fsize)
        return i.filename > j.file
    return (i.fsize > j.fsize)
}
NathanOliver 429 Veteran Poster Featured Poster

And?

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

Here is a good wiki that should start you on your path. This is a NP complete level problem which is going to require a lot of work.

NathanOliver 429 Veteran Poster Featured Poster

What is the problem you are having? Are you getting any errors?

NathanOliver 429 Veteran Poster Featured Poster

line 249-250: do {
lines 267-274:

if(bValid)
{ for ( i = 0; i < nInterval; i++)
  { y = (nStart + 1) % 5;
    viewStudentRecord(c, y);
  }

} while(ch != 'Q' || ch != 'q');
  }

The closing brace where while is at is actually the closing brace for the if statement. the closing brace beneath it is the one for the do statement. You are also missing a closing brace for the function. You really need to indent your code better. The two main ways I have seen are:

line of code;
more code;
if(something)
{
    more code;
    even more code;
    if(another condition)
    {
        even more code here;
    }
    some more code here;
}
last line of code;

// or 

line of code;
more code;
if(something){
    more code;
    even more code;
    if(another condition){
        even more code here;
    }
    some more code here;
}
last line of code;

I personally prefer the first method as you can easily see that the brackets line up.

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

Your algorithm is a little wrong. Here is how you can do it (pseudocode):

string first, second;
// get the data for the string
for i = 0 to i < first size - second size
    if (substring(first[i], first[i+second size]) == second)
        counter++;
NathanOliver 429 Veteran Poster Featured Poster

Herb Sutter has shown that you can use the following to shrink a container down

string(str).swap(str);

This will create a temporary string object with exactlly what is left in str. then it swaps that new smaller string into str and puts the bloated one in the temporary. then the temporary goes out of scope and the resources get released.

NathanOliver 429 Veteran Poster Featured Poster

I'm still rocking a floppy at work but it is a USB external floppy. The machine I have also has a serial port and that was hard to come by. When will computer manufactures realize that stuff built in the 80's-90's still works great today?

NathanOliver 429 Veteran Poster Featured Poster

@ Rafiii - Do not do homework for others that show no effort.

NathanOliver 429 Veteran Poster Featured Poster

What are the errors the compiler is giving you? Al so formating of you code is terrible. Code block should look like either of the following

some line of code;
if (some condintion)
{
    some line of code;
    another line of code;
    if (another condition)
    {
        some line of code;
    }
}

// or

some line of code;
if (some condintion) {
    some line of code;
    another line of code;
    if (another condition) {
        some line of code;
    }
}

I personally perfer the first method because you can clearly see the brackets match. The second method seams to be just as popular if not more so. The biggest thing is find one way of doing your brackets and indentation and stay with it throughout your code.

Good Variable names are another part of good codding.

int m11,m12,m21,m22,m31,m32,m41,m42,m51,m52;

What are these variables for? I have no idea. It looks like from your code that they might be x and y posistions but thats just a guess. You dont seam to do anythig with them after you pass them to makemove() so why not use one set of variables and keep reusing them?

NathanOliver 429 Veteran Poster Featured Poster

-O0 will give you zero optimization and can't remember where I was told this since it was a few years ago but that will definitely cause your code to be very slow. I would recommend using -Og which is:

Optimize debugging experience. -Og enables optimizations that do not interfere with debugging. It should be the optimization level of choice for the standard edit-compile-debug cycle, offering a reasonable level of optimization while maintaining fast compilation and a good debugging experience.

That should give you the best of both worlds.

source: https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html

NathanOliver 429 Veteran Poster Featured Poster

So what seams to be your problem. Just posting your homework will get you nowhere. I will offer to do it for $1000 USD that that is a limited time special offer.

NathanOliver 429 Veteran Poster Featured Poster

This post seems a little nonsensical. "t6" is not a char but a string. What is the type of arraystr? Why are you storing the answer into int's?

NathanOliver 429 Veteran Poster Featured Poster

Well you can either use command line arguments and code your program to accept and use those or you can just call you program and have the program ask you for what it needs.

// example of ussing command line arguments
c:\programFolder\program.exe -inputFile input.txt -outputFile output.txt
// program output here


// example of programing questions
c:\programFolder\program.exe // press enter
Please specify the input file: // enter the input filename and press enter
Please specify the output file: // enter the output filename and press enter
// program output here
NathanOliver 429 Veteran Poster Featured Poster

So what seams to be your problem?

NathanOliver 429 Veteran Poster Featured Poster

Show the code you have now and we should be able to help you modify it.

NathanOliver 429 Veteran Poster Featured Poster

So what exactly do you need help with? Just posting your problem statement and hoping someone will give you code isn't going to work here.

NathanOliver 429 Veteran Poster Featured Poster

getting a runtime error points suggest that you are going out of the bounds of the array. What I wold suggest is that in your get and set methods you put in an if statement that checks to see if you are out of bounds and if you are then print a message. Then you should be able to find out where that is coming from.

NathanOliver 429 Veteran Poster Featured Poster

I personally wouldn't use C++ for .Net programing. I would and have used C#.

NathanOliver 429 Veteran Poster Featured Poster

Line 270: virtual ~Deck():

Notice anything wrong with that?

Lilgenski16 commented: That isnt an error, so there is not anything wrong with it, the : is correct instead of the ; +0
NathanOliver 429 Veteran Poster Featured Poster

If you have access to the source code for program.exe and it isn't very large I would just incorporate that program into the new GUI application. That way you avoid using system calls which should be avoided. If not then you would need to use system calls.

NathanOliver 429 Veteran Poster Featured Poster

You can use file streams.

NathanOliver 429 Veteran Poster Featured Poster

It is possible to do but depending on how big your project is you might not want to do it that way. Calling another exe file requires a system call which incurs a lot of overhead. If it is possible I would just wrap you previous program in a wrapper and then included/call it in your new GUI application.

NathanOliver 429 Veteran Poster Featured Poster

Read a book, take a class, watch you tube tutorials. They're are lots of ways to learn C++, the question is how much time and money do you want to devote to it.

NathanOliver 429 Veteran Poster Featured Poster

I would like to ask why you need to pass your array by value?

NathanOliver 429 Veteran Poster Featured Poster

What is the value of s.cch after you call GetMenuItemInfo()?

NathanOliver 429 Veteran Poster Featured Poster

What is the error you are getting? An LPSTR is just a char* and a LPCSTR is a const char*. Since std::string has operaotr==(std::string, const char*) you should be able to get rid of line 12 and change line 14 to if (caption == s.dwTypeData)

NathanOliver 429 Veteran Poster Featured Poster

line 5: void print(string *ar[]) which becomes
line 5: void print(string **)

line 23 print(&s) which becomes
line 23 print(s)

Since the name of an array is the address of the array. In your code if you put before line 23

cout << s;
cout << &s;

You should get the same value. If you want to get an array in your print function I would just write:

void print(const string * arr, int size)
{
    for (int i = 0; i < size; i++)
        cout << arr[i];
}
NathanOliver 429 Veteran Poster Featured Poster

When dealing with a 2d vector/array the first dimension is the row and the second dimension is the column. If you wanted to go through all of the elements you would need two loops, one for the number of rows and one for the number of columns. Putting that together you get:

std::vector<std::vector<int>> vec;
// load vec
for (std::vector::size_type i = 0; i < vec.size(); ++i)
    for (std::vector::size_type j = 0; j < vec[i].size(); ++j)
        std::cout << vec[i][j] << " ";

Now if you only want to get the values from one column you can see that the second loop is useless since "j" would never change. The code to get just the column then would be

std::vector<std::vector<int>> vec;
// load vec
for (std::vector::size_type i = 0; i < vec.size(); ++i)
    std::cout << vec[i][columnNumber] << " ";

You should be able to get it from there.

NathanOliver 429 Veteran Poster Featured Poster

There are two main ways to delete a list that I know. You can use recursion or you can iterate.

// recursion
void delete(listNode node)
{
    if (node.next != nullptr)
        delete(node.next);
    delete node;
}

// iteration
void delete(listNode node)
{
    listNode temp;
    while (node != nullptr)
    {
        temp = node.next;
        delete node;
        node = temp;
    }
}
NathanOliver 429 Veteran Poster Featured Poster

@rubberman - I think the main reason C++ added the brace initialization is that it now allows for more robust object initialization which enhances RAII. With brace initialization we can now write code like:

std::vector<int> numbers {1,2,3,4,5};

Instead of:

int array temp {1,2,3,4,5};
std::vector<int> numbers(temp, temp + 5);

Here are some addtional references for you:

http://en.cppreference.com/w/cpp/language/aggregate_initialization
http://en.cppreference.com/w/cpp/language/list_initialization