CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Homework Help

  1. #1
    Join Date
    May 2013
    Posts
    1

    Homework Help

    Help! I have a homework assignment due this afternoon and can not get it working. Here is a little more details about the assignment.

    Question3 (Strings & Files) (20 marks)

    Write a well-commented C++ program that reformats and outputs the date. Prompt the user to input the date in the format dd/mm/yyyy and outputs it in this format month, dd, yyyy. For example, 07/06/2012 is displayed as June 07, 2012. You are provided with the file months.txt containing the months and their corresponding numbers, for example 01January 02February etc. Use getline(monthsFile,monthString) to read in a string from the file, and use the monthString.find() function to search for the number and extract the corresponding month.


    -confused by the way she told me to use getline(monthsFile,monthString) => if I just do it like this I only get the first line from the txt file (01January)
    -if I try putting all the months on one line in the txt file (which i'm not even sure i'm allowed to do), I'm not sure what to do for the length of my substring output. if I make it long enough to fit longer months like September, someone entering may gets both may and june in the output
    -if I input all the months into separate variables, I'm not sure how to make it only output the month entered by the user

    the months.txt file is as follows:

    01January
    02February
    03March
    04April
    05May
    06June
    07July
    08August
    09September
    10October
    11Novmber
    12December

    Thanks for your help!

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Homework Help

    Post the code you have produced so far and we'll provide advice and guidance. As this is homework, we can't write the code for you. Also you should read
    http://forums.codeguru.com/showthrea...ork-assignment

    -confused by the way she told me to use getline(monthsFile,monthString) => if I just do it like this I only get the first line from the txt file (01January)
    yes for the first use of getline. However, if you put this into a loop until end of file is reached then you can read the whole file.

    -if I input all the months into separate variables, I'm not sure how to make it only output the month entered by the user
    The don't input into separate variables! Either read the whole file into an array (or better vector) and then access the required element of the array or read until the required month number has been found and then use the corresponding month name.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured