CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 3 123 LastLast
Results 1 to 15 of 44
  1. #1
    Join Date
    Jan 2014
    Location
    Portland, OR
    Posts
    34

    Red face Looking for a Mentor

    Hi there. I'm currently a student in a CS degree and I'm looking for someone to mentor/tutor me. I'm looking for someone that can help me with challenging assignments/topics, have in-depth conversations regarding the topics I'm learning about and just all around help me out.

    We are coding in C++ and using Visual Studio 2013.

    Thanks!

    Jenn

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Looking for a Mentor

    What is your C++ question?
    Last edited by VictorN; January 12th, 2014 at 04:16 PM.
    Victor Nijegorodov

  3. #3
    Join Date
    Jan 2014
    Location
    Portland, OR
    Posts
    34

    Re: Looking for a Mentor

    I'm creating a program that will read in a data file regarding vehicle registration per household, then calculates the registration tax for each vehicle, the household total and the overall total. Then writes the household totals into an external file as well as on the screen.

    I think I've figured out how to read in data, write out the data and calculate the fees. But I don't know how to create the loop that will read a line, do the calculation and writing, store the information for screen display, then moves onto the next line.

  4. #4
    Join Date
    Jul 2013
    Posts
    576

    Re: Looking for a Mentor

    Quote Originally Posted by spideyflygirl90 View Post
    I'm currently a student in a CS degree and I'm looking for someone to mentor/tutor me.
    It's much better to team up with class mates. Be part of an informal study group. That's how you get through college (learning and having fun together).
    Last edited by razzle; January 12th, 2014 at 05:29 PM.

  5. #5
    Join Date
    Jan 2014
    Location
    Portland, OR
    Posts
    34

    Re: Looking for a Mentor

    I'm doing an online program so no one in the area. I've put the same feelers out there asking for some help but no one else seems to get it either. Haha

  6. #6
    Join Date
    Jul 2013
    Posts
    576

    Re: Looking for a Mentor

    Well, since it's an online course it can't be considered cheating to search the internet.

    http://learnedstuffs.wordpress.com/2...-reading-in-c/

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

    Re: Looking for a Mentor

    Quote Originally Posted by spideyflygirl90 View Post
    I'm creating a program that will read in a data file regarding vehicle registration per household, then calculates the registration tax for each vehicle, the household total and the overall total. Then writes the household totals into an external file as well as on the screen.

    I think I've figured out how to read in data, write out the data and calculate the fees. But I don't know how to create the loop that will read a line, do the calculation and writing, store the information for screen display, then moves onto the next line.
    Possibly the easiest way to have a loop that reads some data from a file until the end and processes that data is something like

    Code:
    ifstream infile("infilename");
    
         while (infile >> input1 >> input 2 >> etc etc etc) {
            //process data
         }
    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)

  8. #8
    Join Date
    Jan 2014
    Location
    Portland, OR
    Posts
    34

    Re: Looking for a Mentor

    Quote Originally Posted by razzle View Post
    Well, since it's an online course it can't be considered cheating to search the internet.

    http://learnedstuffs.wordpress.com/2...-reading-in-c/
    haha. Which is why I'm here hoping for some discussion/help :-) I'll check that out for sure!

  9. #9
    Join Date
    Jan 2014
    Location
    Portland, OR
    Posts
    34

    Re: Looking for a Mentor

    Quote Originally Posted by 2kaud View Post
    Possibly the easiest way to have a loop that reads some data from a file until the end and processes that data is something like

    Code:
    ifstream infile("infilename");
    
         while (infile >> input1 >> input 2 >> etc etc etc) {
            //process data
         }
    My assignment has to be modular so have at least 3 differently defined codes. So I'm trying to write a

    int readCode()
    int writeCode()
    int calculateFees()
    int main()

    maybe an int displayScreen() but I think it would probably be easier to put this in main.

    so I wrote readCode to do just one line, same with writeCode and calculateFees. then I'm trying to put my loop within main to call each of the three functions and add to displayscreen before iterating the loop.....

  10. #10
    Join Date
    Jan 2014
    Location
    Portland, OR
    Posts
    34

    Re: Looking for a Mentor

    So I have

    int getCode()
    {....}

    within my int main() while loop, can I use a boolean statement like: while (getCode == true) {...} ??

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

    Re: Looking for a Mentor

    If you posted some of the code you're written and an example of the data file we'll be able to advise further. It could be that you just need to have a loop that just calls these functions in turn. The slight issue with having a function for readCode() is dealing with errors and end-of-file condition.

    Basically the program then becomes in pseudocode something like

    Code:
    while (file-no-error) {
        ReadNextRecordFromFile;
        CalculateFees;
        WriteTotalsToFile;
        DisplayInformation;
    }
    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)

  12. #12
    Join Date
    Jan 2014
    Location
    Portland, OR
    Posts
    34

    Re: Looking for a Mentor

    Okay. This is going to be kind of a long post ;-) I'm still pretty new to programming. This is only like my 3rd class.

    So my assignment is to read in a data file of vehicles registered per household.
    Input ex:
    111111 A ABC123 2012 36666 M XYZ7892005 15555
    222222 A DDD333 1999 22222
    which follows the form of:
    HouseholdID VehicleClass (Motorcycle or automobile) LicensePlate VehicleYear Original Cost

    So I have to figure out registration fees based upon the age and original cost (I have the formulas for this given to me).
    Then I have to output 1 file VEHICLES.txt which lists the vehicles and their registration costs
    Ex:
    A ABC123 1160.65
    M XYZ789 341.32
    A DDD333 355.11 (these may not be accurate calculations just an example)

    Also an output file HOUSEHOLDS.txt which lists the house id and total registration fees for that house hold (adding all vehicle fees)
    Ex:
    111111 1501.97
    222222 355.11

    Then display it on screen in the format:
    Household ID Number Vehicles Registered Total Charges
    ---------------------------------------------------------------------
    111111 2 1501.97
    222222 1 355.11

    All the decimals need to line up in my outputs as well (ie, look professional). I can't use global variables. And I have to be modular - using different functions with the main basically calling the other functions.

    Okay so for my code, here's what I have so far....I know I still have a lot to do. Like I said, I'm new to this :-D

    /*The purpose of this program is to read in data from an existing file containing information regarding households and registered vehicles.
    The program will then calculate how much the registration fees will be based upon original cost and age of the vehicle.
    The program will display this information by vehicle, household, and finally a total for the county.*/

    #include <iostream>
    #include <fstream>
    #include <iomanip>
    #include <string>

    using namespace std;

    int getData(int houseID, int vehicleYear, int originalCost, string vehicleClass, string licensePlate)
    {
    ifstream myFileIn;
    myFileIn.open("REGISTER.txt");
    if (myFileIn.is_open() == false)
    {
    cout << "I'm sorry. The file " << myFileIn << " cannot be opened. Please press enter to exit the program and try again. Thank you." << endl;
    return 0;
    }
    else
    {
    myFileIn >> houseID >> vehicleClass >> licensePlate >> vehicleYear >> originalCost;
    }
    }

    int writeDataVehicles(string vehicleClass, string licensePlate, double registrationFees)
    {
    ofstream vehiclesOut;
    vehiclesOut.open("VEHICLES.txt");
    vehiclesOut << vehicleClass << setw(8) << licensePlate << setprecision(2) << setw(8) << right << registrationFees << endl;

    }

    int writeDataHouseholds(int houseID, double totalHouseholdFees)
    {
    ofstream householdsOut;
    householdsOut.open("HOUSEHOLDS.txt");
    householdsOut << houseID << setw(8) << totalHouseholdFees << endl;

    }

    int calculateFees(int originalCost, int vehicleYear, double licenseFee, double ownershipTaxA, double ownershipTaxM, string vehicleClass)
    {
    const double roadFeeA = 24;
    const double roadFeeM = 12;
    licenseFee = 0.0025 * originalCost;
    double vehicleAge = 2014 - vehicleYear;

    if (vehicleClass = A)
    {
    if (vehicleAge <= 5)
    {
    ownershipTaxA = (0.03 * originalCost) - ((0.015 * originalCost) * vehicleAge);
    }
    else if (5 < vehicleAge <= 10)
    {
    ownershipTaxA = (0.0275 * originalCost) - ((0.012 * originalCost) * vehicleAge);
    }
    else if (10 < vehicleAge <= 15)
    {
    ownershipTaxA = (0.025 * originalCost) - ((0.009 * originalCost) * vehicleAge);
    }
    else
    {
    ownershipTaxA = 20.00;
    }
    }
    else if (vehicleClass = M)
    {
    if (vehicleAge <= 5)
    {
    ownershipTaxM = (0.025 * originalCost) - ((0.009 * originalCost) * vehicleAge);
    }
    else if (5 < vehicleAge <= 10)
    {
    ownershipTaxM = (0.0225 * originalCost) - ((0.009 * originalCost) * vehicleAge);
    }
    else if (10 < vehicleAge <= 15)
    {
    ownershipTaxM = (0.02 * originalCost) - ((0.009 * originalCost) * vehicleAge);
    }
    else
    {
    ownershipTaxM = 10.00;
    }
    }
    }

    int main()
    {
    int houseID, vehicleYear, originalCost;
    string vehicleClass, licensePlate;
    double registrationFees, totalHouseholdFees, licenseFee, ownershipTaxA, ownershipTaxM;

    while (getData()
    {

    }
    }

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

    Re: Looking for a Mentor

    When posting code please format your code properly first and use code tags. Go Advanced, select the code and click '#'.

    Code:
    111111 A ABC123 2012 36666 M XYZ7892005 15555
    From this, there seems that there can be more than one vehicle per household stated on the same line in the data file? Is that right? Also should there be a space before 2005 (ie should the data actually be XYZ789 2005)?

    Also, in getdata(), you'll need to open the file in main() (or have another routine to do this) so that you don't keep opening the file everytime you read a line. The same goes for the various write functions as well. Often the names of the files would be defined as a const string at the top of the program so that it can easily be changed without having to search all of the program for them.

    Have you come across map yet in c++ STL? If you have then using it is going to make the issue of getting the totals per household easier.
    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)

  14. #14
    Join Date
    Jan 2014
    Location
    Portland, OR
    Posts
    34

    Re: Looking for a Mentor

    Yes. The number of vehicles per household is unknown. (As in it could vary based on data input file. Yes XYZ789 2005. Sorry.

    I didn't know about the code box thing. I will do that next time. My apologies.

    So I could write an openFile() that opens both the input and output files...correct? then have getdata() and writedata()? Would that be the easier/proper route or would it be better to write open into main()?

    Writing the files as const string count as a global variable? Or because it's a constant, it's not a variable?

    I have not learned map yet. I'm still very new to programming. Struggling without someone to discuss it with too! Haha. But I'm trying :-)

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

    Re: Looking for a Mentor

    If the input data can have lines of varying length that conatin 1 or more sets of data relating to a specified household, then you have a very different input acquisition problem from the way you are doing it. You don't know how many sets of vechicle data there are on a line for the household so your getData() routine won't work properly.

    Basically, there are two ways to approach this.
    1) Use GetLine() to read a whole line of data from the file at once into a string and then parse the string which has a format of household <vechicle> {<vechicle>} where <vechicle> has the format VehicleClass (Motorcycle or automobile) LicensePlate VehicleYear Original Cost

    2) Use the stream extraction method you are currently using, but if you get a single letter for the house ID then you have new vechicle data for the previous household.

    Neither is exactly trivial and which way you opt to go will depend largely upon what you feel most comfortable with.
    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)

Page 1 of 3 123 LastLast

Tags for this Thread

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