Urgent!!! I need help with this C++ homework!!!

Discussion in 'Programmer's Corner' started by Silvi, Sep 26, 2011.

  1. Silvi

    Thread Starter New Member

    Sep 26, 2011
    1
    0
  2. DumboFixer

    Active Member

    Feb 10, 2009
    219
    34
    Show us what you've done so far and we'll point you in the right direction.

    (this forum is not a free homework service)
     
  3. MrChips

    Moderator

    Oct 2, 2009
    12,449
    3,364
    All persons requesting solutions to homework questions must realize that it is counter intuitive and counter productive to ask for URGENT!!! help. I certainly would not give it to you in a hurry.
     
  4. someonesdad

    Senior Member

    Jul 7, 2009
    1,585
    141
    When I see "Urgent!!", all it usually means is we're dealing with a lazy student who put his homework off until the last minute. The leads to the sympathy meter are broken, which mean it doesn't even twitch. :p
     
  5. DumboFixer

    Active Member

    Feb 10, 2009
    219
    34
    Remind me never to put "Urgent" in a title of a topic I start :)
     
  6. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    It's truly remarkable the number of students who believe that a lack of planning on their part should constitute an emergency on our part.
     
  7. ajm113

    Member

    Feb 19, 2011
    176
    5
    Why just register on a website just to ask people to do your homework? Doesn't your collage have some sort A++ student in C++ that can give you tutoring? Cause really to me, this question sounds like a walk in the park that I could write myself in 10 minutes. :p
     
  8. someonesdad

    Senior Member

    Jul 7, 2009
    1,585
    141
    We've got to learn to be more sarcastic. This Silvi made way too many posts.
     
  9. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    The problem that the OP wanted served on a silver plate. Is a something you can read about in every textbook about C/C++ DoH!
     
  10. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    What? You guys don't just download the codes for everything you do?
     
  11. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Yes that is correct. And you can learn a lot by looking at and/or modify example code and code from others. But to me it seems like the OP just looked for an easy way out of some homework. It had been quite different if the OP at least had shown some coding attempt and asked for help
     
  12. RiJoRI

    Well-Known Member

    Aug 15, 2007
    536
    26
    I kinda wonder if Silvi was in panic mode, or didn't understand the question, or both. I suspect we'll never know...

    --Rich
     
  13. PNeil

    New Member

    Oct 27, 2010
    11
    1
    #include <fstream>

    using namespace std;

    int main()
    {
    int num1=0, num2=0, num3=0, sum=0;

    ifstream fin("number.in");
    ofstream fout("sum.out");

    // read in the numbers
    fin >> num1 >> num2 >> num3;

    sum=num1+num2+num3;

    // write results to files
    fout << "Sum of the digits is " << num1 << "+" << num2 << "+" << num3 << " = " << sum;

    fin.close();
    fout.close();

    return 0;
    }
     
  14. upand_at_them

    Active Member

    May 15, 2010
    246
    29
    You know...The proper response to someone who asks you to do his homework for him is to...Give him the wrong answer. He'll quickly learn.
     
  15. ajm113

    Member

    Feb 19, 2011
    176
    5
    I may as well give him the real answer to this... Since PNeil as we all can tell doesn't clearly work. I mean look at it! He doesn't even use cout and use proper error handling! D:


    Code ( (Unknown Language)):
    1.  
    2.  
    3. #include <iostream>
    4. #include <string>
    5. #include <sstream>
    6. #include <string.h>
    7. #include <stdio.h>
    8.  
    9. using namespace std;
    10.  
    11. int main(int argc, char *argv[])
    12. {
    13.      unsigned short iValue1;
    14.      unsigned short iValue2;
    15.      unsigned short iSum;
    16.  
    17.      //Welcome the user!
    18.      cout << "Welcome to my program! Please enter a value! ";
    19.  
    20.      cin >> iValue1;
    21.  
    22.      cout << "\n\nValue 2:" << endl;
    23.  
    24.      cin >> iValue2;
    25.  
    26.     //Thank the user and write to the file.
    27.     //This part is very hard and long.
    28.     iSum = iValue1 + iValue2;
    29.  
    30.    char* buffer;
    31.    buffer = new char[iSum];
    32.  
    33.    int counter = 0;
    34.   string fileName = "output_";
    35.  
    36.   //You can change the extension if you like. ;)
    37.   string ext = ".bin";
    38.  
    39.    cout << "Please wait.... Calculating..." << endl;
    40.    for(;;)
    41.    {
    42.      fileName += counter;
    43.      fileName += ext;
    44.       counter++;
    45.  
    46.       FILE * fp = fopen(fileName.c_str(), "w");
    47.       fileName = "output_";
    48.  
    49.       if(!fp)
    50.       {
    51.        cout << "ERRROR: A epic fail has happened!" << endl;
    52.        break;
    53.       }
    54.  
    55.       fwrite (buffer, 1 , iSum , fp);
    56.  
    57.     fclose(fp);
    58.    }
    59.  
    60.     cout << "PROGRAM ENDED...." << endl;
    61. //Make sure we clear some memory! :D
    62. delete [] buffer;
    63.  
    64.    return 0;
    65. }
    66.  
    67.  
    Now that's the pro way of doing things! Just compile that and drop the executable to your teacher! ;)
     
    Last edited: Oct 5, 2011
Loading...