deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So stop getting your knickers in a twist.

Please consider taking your own advice. You seem to be the only one who has a problem with my responses, so maybe the problem is you being overly sensitive and not me being unhelpful, rude, or arrogant.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Please don't just post your homework assignment in the expectation that someone will do it for you. We require proof of effort, and then provide help, not free solutions for lazy people.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Get a choice from the user, then use an if..else statement to select between the operations. I'm not going to write it all for you.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

urm...i just want to know how to write a program for calculate division,multiply,addition and subtraction.

No offense, but this is a meaningless request. Do you want something simple like this?

#include <iostream>

using namespace std;

int main()
{
    int a = 123, b = 5;

    cout << a + b << '\n';
    cout << a - b << '\n';
    cout << a * b << '\n';
    cout << a / b << '\n';
}

My guess is not, otherwise you'd probably not be asking for help. So what you need to do is be as specific as possible concerning exactly what you want.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

ifstream file(fileName.c_str(), ios::in);
ifstream fin("Show.txt");

Which of those objects are you actually using? That's the problem.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I have been doing research but to no avail.

Then either you don't really know what you want to do, which would make researching how to do it difficult, or you haven't been looking very hard. Please click the link in my previous post.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If I were to implement this into the code I already have where would I put it?

It's a replacement for your code.

Will your code work for asking the user to input the .txt file of their choosing?

No, you'd need to add that part. Though it shouldn't be a big deal as you clearly already know how to do it (that part of your code is correct).

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm guessing this is for an arbitrary precision math solution? If so, have you don't any research at all? Do you have a rough idea of how you want the "system" to work? And by how you want it to work, I mean more than the vague concept of "using" the basic arithmetic operations.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

TextChanged fires every time the value in the text box changes, so if you don't want to have a message box each time you press a key, you probably want to use something like a Leave or Validating event rather than TextChanged.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

do
#include <conio.h>
#include <windows.h>

The rest of the world may not use the same compiler and OS as you do. Both conio.h and windows.h are dependent on the implementation. Further, this problem can be solved without resorting to non-portable libraries. You don't have to call gotoxy() when it's a simple matter of printing a few space characters.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

http://www.ics.uci.edu/~eppstein/161/960109.html

That should help you boil it down to the task of handling matrix multiplication.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The problem with calloc() stems from underlying bit patterns not being all bits zero. Most notable in history is how null pointers are represented (read more here). Once you understand that problem, it's pretty easy to see how memset() to all 0s on a pointer type won't necessarily produce a null pointer. The same problem exists for essentially any type that isn't strictly integral.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It doesn't matter if they are still on the basics, you should still help....and if you don't want to help then don't reply!!

I don't see any lack of helping in this thread, to what are you referring? Perhaps you should actually read the thread in its entirety before acting like a net nanny.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Have you tried searching for those terms in google?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What is this code trying to so ?

It's trying to create a simulated 2D array without calling malloc() for each row but still allow array indexing for both dimension. Let's say you want a 2D array, but the size must be a runtime value. malloc() is essentially your only option (barring C99 VLAs, but we'll ignore those for now).

There are basically three ways you can go about it. First is a straight allocation to a pointer:

#include "stdio.h"
#include "stdlib.h"

int main(void)
{
    int rows = 3, cols = 4;
    int *p = malloc(rows * cols * sizeof *p);
    int i, j, k = 0;

    /* Populate */
    for (i = 0; i < rows; ++i) {
         for (j = 0; j < cols; ++j)
             p[i * cols + j] = ++k;
    }

    /* Display */
    for (i = 0; i < rows; ++i) {
         for (j = 0; j < cols; ++j)
             printf("%4d", p[i * cols + j]);

         putchar('\n');
    }

    /* Release */
    free(p);

    return 0;
}

Notable in this option is only a single call to malloc(), but also the awkward indexing calculation. What we'd really like to do is index the simulated array just like we would a real 2D array: p[i][j]. But to do that we need to simulate a 2D array in the form that it would be as a real array, that is, each p[i] evaluates to a pointer to the first element of the subarray. This leads …

I_m_rude commented: bow to you james sir! hats off to you! +2
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I am not getting the reason for this error and how to rectify it.

A segmentation fault is when you try to access memory outside of your address space. It's nearly always caused by dereferencing an invalid pointer address or using an out of range index for an array. Those two things should be the first you look for.

Since I don't have the rest of your code or your files, you'll have to debug this yourself. Any decent debugger will let you run until a failure; you can at least see which line it occurs on and whatever pointer or index values are set at the time.

Another thing to consider is the 16-bit boundary. Since you guesstimated 44,000, and that's close to 32,767, and Turbo C is distressingly common, you'll probably want to consider issues where 16-bit integers are overflowing somewhere and wreaking havoc. If you're using Turbo C, of course.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Any specific reason as I guess this is due to the version of DOS ?

The most likely reason is that I haven't worked with assembly in several years and while the logic was sound, the actual code is subtly (or blatantly) wrong somewhere.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

That is likely to generate a lot of object code,but is said to be faster.

Until the added object code size causes excess cache misses. ;) Despite the common belief, inline functions aren't guaranteed to improve anything, and could just as easily make things worse or have no measurable effect.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I am getting this error when executing the code.

I guess you'll have to use the same logic and write working code then. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's supposed to represent 20000 seconds = 5 hours, 33 minutes and 20 seconds but it comes out as 12 seconds

Yes, 20000 % (5 + 33) is indeed 12. Your sec variable has the correct value of 20, but you don't print it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Does that include compiling the code or are you using a C++ interpreter? Because you don't just "run" C++ source code. Anyway, I can't tell you what's possible or not since you're closer to the problem than I am, but editing the code 100 times with a shell script seems silly from my perspective, especially when the only change is the sequence number after a couple of file names.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It seems like a better solution would be to edit the C++ code to accept input and output file names from the calling process, or run the whole thing in a loop a requested number of times from the calling process.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Your output would be correct if you printed sec as the number of seconds instead of RemainderOfSeconds. RemainderOfSeconds isn't meaningful anyway because you throw away the difference between hours and minutes. Using your example numbers, what is 20000 % (5 + 33) supposed to represent?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Here's pseudocode for what you're doing:

cx = 10

while cx <> 0
    while cx <> 0
        int 21h
        dec cx
    loop

    dec cx
loop

So cx starts out as 10 and gets decremented to 0 by the inner loop. Then the outer loop decrements it again to make it negative and tests it against zero. cx is obviously not zero at this point, so the outer loop repeats. cx is still not zero, so the inner loop repeats.

Now you're looking at an underflow situation, where the inner loop will repeat until cx underflows, and hopefully wraps back around to 0. But ultimately this code represents a bug and should be fixed.

My guess would be that you're trying to use cx to represent two things (rows and columns) but the two nested loops are stepping on each other. You can get around that by saving and restoring cx around the inner loop:

; Print a right triangle

mov cx, 10     ; Decreasing number of rows remaining
mov ax, 1      ; Increasing number of asterisks per row

rows:
    mov dx, cx ; Save cx for later
    mov cx, ax ; Use ax's value for the inner loop counter

    cols:
        int 21h
    loop cols

    mov cx, dx ; Restore cx for the outer loop
    inc ax     ; Add an asterisk for the next row
loop rows

Another alternative would be to eschew the loop instruction and do it manually with two registers instead of one.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I have made it through only part a.

Then please post the code to prove you've done it. Our rules clearly state that we require proof of effort on homework.

b) allow user to print array in ascending or descending order.

I imagine either you've learned about bubble sort, or you're allowed to use Array.sort().

c) allow user to search for specific int value (you can use your code from part 2)

Presumably you've already done part 2, so what's the problem?

d) allow user to view max value, min value, average and standard deviation of the array values.

Can you do this manually? If you can't do something on paper with a handful of numbers then you have no hope of telling a computer how to do it.

e) user controls must be provided and can be as a command line prompt and response.

That's a fancy way of saying that you need a user menu for selecting which action to take and for acquiring the initial array size. But since you've accomplished part a, you shouldn't have any problems with this part either.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

And i found forums the best way for me to learn.

People will quickly become tired of teaching you basics that are written in every beginner book in print, especially if you try to write programs that are far beyond your current level.

however it seems to have a delay time, can i add this code directly to mybase.load ? :)

I'm not sure what you mean by "delay time", but the items won't be added until after you click levelcombo to fire the event. You could certainly add the items from your Load event, and unless they depend on user action or are completely static that would probably be the best approach. If they're static (ie. set at design time) then you should consider creating them at design time and avoiding the overhead of generating them at runtime.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Loops are programming 101. You really shouldn't be trying to write a GUI until you at least understand the most basic core concepts of the language. It's also not very wise to jump right in without any kind of beginner text; you should find yourself a book on VB.NET, any of them will do.

kvprajapati commented: Words :) +14
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Um...have you considered calling Add() in a loop from 1 to 100?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Our rules clearly state: "Do provide evidence of having done some work yourself if posting questions from school or work assignments".

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

at link is showed input/output of function but no pseudocode to implementation .-. useless...

And in this thread (the 4th post, to be precise) is a full working implementation. Hmm...

also find some code for ftoa() but there is some bugs or what...

ftoa() is a significantly more difficult function to write than itoa(). itoa() really is as simple as this:

char *itoa(int value, char *s, int radix)
{
    const char *digits = "0123456789abcdefghijklmnopqrstuvwxyz";
    unsigned long ulvalue = value;
    char *p = s, *q = s;
    char temp;

    if (radix == 10 && value < 0) {
        *p++ = '-';
        q = p;
        ulvalue = -value;
    }

    do {
        *p++ = digits[ulvalue % radix];
        ulvalue /= radix;
    } while (ulvalue > 0);

    *p-- = '\0';

    while (q < p) {
        temp = *q;
        *q++ = *p;
        *p-- = temp;
    }

    return s;
}

The corresponding ftoa() appears functional on the surface, and will work for the most part:

char *ftoa(double value, char *s, int precision)
{
    char *p = s, *q = s, *end;
    double ipart, fpart;
    char temp;

    if (value < 0) {
        *p++ = '-';
        q = p;
    }

    fpart = modf(fabs(value), &ipart);

    /* Build the integer part of the mantissa */
    while (fabs(ipart - 0) > 1) {
        *p++ = (char)(fmod(ipart, 10) + '0');
        ipart /= 10;
    }

    if (p == s || (!isdigit(s[0]) && p == s + 1)) {
        /* There were no digits before the decimal point; …
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Will i have two executables. Each for an environment?

Yes. Technically you could write an app for one environment and rely on emulation like Wine for running on the other environment, but if you want native support then there will be two executables.

Do i have to write two totally different codes for different enviroments.

It depends. If you use platform dependent APIs (such as Windows UI elements) or do a lot of system level stuff then there will be pieces of code that must be ported.

If yes, is there anyway to MAP the code from one enviroment to another.

Not so much, though you can use platform independent solutions wherever possible. And when you have no choice, isolate the non-portable code as much as possible by wrapping it in classes and functions that can be more easily swapped out with a different implementation.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Why is the code not swapping names??

Because you're not swapping names. You're not even swapping Students. You're swapping local references (copies of references that are passed to swap()), which ultimately doesn't change the original references.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

why havn't we yet heard of a story about a virus that burned out the whole hardware ?

Primarily because it's impractical for the same reason you don't hear about Linux or OSX viruses that often. The dependencies are fairly extreme, so the virus would only work on very specific hardware configurations.

is the OS protecting PC??

Defense mechanisms are in place, though not necessarily against malicious software. For example, if you've ever done any overclocking, you'll probably have encountered the situation where your processor overheats and the machine hard stops to avoid damage. That's a defense mechanism against overheating of the CPU.

Manually manging memory means, assigning every integer to memory by typing its address by the programmer.

That's not how it works, unless you're targeting a specific address like old DOS' real mode VGA locations. More often you're using the stack space provided by the OS and simply adjusting the stack pointer to reserve bytes for an object. Even in assembly language we don't manage memory in the way you've described unless our program is the operating system.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It really depends on what you enjoy, but if you're just trying to get into programming as a career then it would be wise to take what you can get and use that to build up experience. Once you have a little more experience you can make educated choices as to what you want and also be in a a better position to make it happen.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

maybe

Discussion of virus implementation is prohibited on Daniweb. But yes, it's possible to physically harm hardware through software, if one is so inclined.

Also "Does the programmer have to control memory manually in Assembly ?"

Yes, unless you call into a library that manages memory for you.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Sure. You'd wrap the lines in a function and simply call the function when you need those lines to be executed:

void show_powerlevel()
{
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 3);
    cout << "Congratulations your power level is now" << PowerLevel << endl;
}

...

// Use it like this:
show_powerlevel();
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Once you're connected to a wifi network, the process of using it is the same as a wired network. Have you read Beej's guide to network programming yet?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Im pretty confused over bool functions too.

They're functions that return a boolean value. Really not that different from a void function except for the return value.

Apparently the program runs through the bool enqueue function twice. If array size is 0, the next positive input will cause the array to grow to array size 2.

That's because you treat an empty queue as an error condition and fail to insert the item. This is somewhat nonsensical since adding to an empty queue shouldn't be a problem except in unrealistic degenerate cases like a queue of size 0.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

How exactly are we talking here, because scanf() is a rather complex function. Ignoring for a moment that there are actually 6 functions in the scanf() family that have a slightly different interface each, the declaration of scanf() itself is like so:

int scanf(const char *fmt, ...);

The definition will probably defer to one of the vscanf() functions:

int scanf(const char * restrict fmt, ...)
{
    va_list args;
    int rv;

    va_start(args, fmt);
    rv = vfscanf(stdin, fmt, args);
    va_end(args);

    return rv;
}

Which in turn will likely call into an internal function for the actual work of parsing the format string and doing string to type conversions. Let's say you wanted to write your own scanf() that only supports %d and with no real error checking as characters are extracted from the stream. It might look like this:

int myscanf(const char *fmt, ...)
{
    int converted = 0;
    va_list args;

    va_start(args, fmt);

    while (*fmt) {
        if (*fmt++ == '%') {
            if (*fmt == 'd') {
                /* Parse and convert an integer */
                char buf[BUFSIZ];
                int i = 0, ch;
                char *end;

                /* Read up to whitespace */
                while ((ch = getchar()) != EOF && !isspace(ch))
                    buf[i++] = (char)ch;

                if (i == 0)
                    break; /* No valid characters */

                /* Attempt the conversion */
                *va_arg(args, int*) = (int)strtol(buf, &end, 0);

                if (*end)
                    break; /* A complete conversion failed */

                ++converted;
            }
            else {
                break;
            }
        }
    }

    va_end(args);

    return converted ? converted : EOF;
}

To …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You cant just use gotoxy(num, anothernum); and increment or decrement them in the for(int i) loop??

What if gotoxy() isn't supported by the compiler?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Well, you could use just a 2D array:

int marks[3][5]; // 5 marks for 3 students.

But that would be less readable, in my opinion, than an array of structures:

struct Student {
    int marks[5];
};

Student students[3];
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You create a new list on every iteration of the loop. Move the definition of ll outside of the loop and it'll work better.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's a fake. It acts like an array for the most part, but isn't an array. Have you considered looking up the definition of "simulate"? That's exactly what it means here.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Then ask a specific question so that we don't have to read your mind!

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

if i allocate memory to a pointer and make it an array , then is it now an array ?

No, but it can largely be used to simulate an array.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but in initial post, u said u can so ? why ?

Obviously I didn't understand your question.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

is it valid to do so ?

No, it's not valid. Arrays are not pointers, they're arrays. You can use malloc() and a pointer to fake an array, but it's not natively an array. Likewise, in many cases an array will be converted into a pointer, but it's not natively a pointer.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Yes, you can use malloc() to allocate a simulated array of int or char. What were you trying to do that prompted this question?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Daniweb is not rent-a-coder. If you have a question, ask it. If you only want someone to do your homework for you, please be kind enough to piss off.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Does the number of functions in a program affect performance?

It can. There's a certain measure of overhead in calling a function at runtime.

Is writing a lot of functions in a program a good practice?

Not if there's no reason for writing "a lot" of functions. Programs should be structured in a way that makes them as readable as possible without negatively affecting performance.