#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    8
    Rep Power
    0

    Working with Classes


    Hello, I am currently enrolled in a class this semster where we must work with classes the professor has completed most of lab, however I am still stuck. I am not looking for answers, only a push in the right direction

    If you could give me any guidance, I would appreciate it.


    Below is my professors response






    This program will give you experience and practice with:

    a struct and a class.

    ------------------------------------------------------------
    Input
    ------------------------------------------------------------

    A series of records of the form

    A char student name called studentName
    A string address called theAddress
    A string city, called theCity
    A char 2-letter state code called stateCode [3]
    An int zip code called theZip

    These will be stored in a struct, so mind the notation.

    The dummy record name will be theDummy.

    These records will live in studentFile

    ------------------------------------------------------------
    Processing
    ------------------------------------------------------------

    I am GIVING YOU most of Lab 8.

    All YOU have to do is finish the methods!

    The class is completely done! Do NOT CHANGE IT!!!

    The main module is completely done! Do NOT CHANGE IT!!!


    Code:
     
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* Lab 8 Working with classes                                   */
    /*                                                              */
    /* Your name(s) here                                            */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* #includes                                                    */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    #include <iostream>
    #include <iomanip>
    #include <fstream>
    using namespace std;
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* struct Definition for  theInputs                             */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    struct theInputs
    {
    
    char   studentName [20];
    string theAddress;
    string theCity;
    char   stateCode [3];
    int    theZip;
    
    };
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* Class definition for  theStudent                             */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    class theStudent
    {
    
    private:
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* Declare variables global to the class                        */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    fstream studentData;
    
    theInputs penguinPete;
    
    char stateSearch [3];
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* Prototypes for the class methods                             */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    public:
    
    theStudent ();
    
    int  getStudentName ();
    void getRestOfInfo ();
    void displayOutput ();
    void evaluateState ();
    
    };
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* Constructor                                                  */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    theStudent :: theStudent ()
    {
    
    studentData.open ("studentFile", ios :: in);
    
    cout << "What state are you looking for?"
        << endl;
    
    cin.getline (stateSearch, 3, '\n');
    
    cout << "\033[2J\033[H"
         << endl
         << endl
         << "State Report"
         << endl
         << endl;
    
    }
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* Method getStudentName                                        */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    int theStudent :: getStudentName ()
    {
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* Read the student name from the file                          */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* If the name is not "theDummy" return 1, else return 0        */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    
    
    }
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* Method getRestOfInfo                                         */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    void theStudent :: getRestOfInfo ()
    
    {
    
    char junk [20];
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* Prompts/read for rest of input                               */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    
    }
    
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* Method DisplayOutput                                         */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    void theStudent :: displayOutput ()
    {
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* Display output                                               */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* Produce output                                               */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    
    
    }
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* Method evaluateState                                         */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    void theStudent :: evaluateState ()
    {
    
    
    
    
    }
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* Main module                                                  */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    main ()
    {
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* Main module variables                                        */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    theStudent thePerson;
    
    int thereIsValidStudent;
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* Set screen for proper formatting                             */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    cout << setiosflags (ios :: fixed)
        << setprecision (0);
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* Processing                                                   */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    thereIsValidStudent = thePerson.getStudentName ();
    
    while (thereIsValidStudent)
    
          {
    
          thePerson.getRestOfInfo ();
          thePerson.displayOutput ();
          thePerson.evaluateState ();
    
          thereIsValidStudent = thePerson.getStudentName ();
    
          }
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* End                                                          */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    }
    ------------------------------------------------------------
    Output
    ------------------------------------------------------------

    For each person, display eight lines

    name
    address
    city, ST zip

    Resident of ST or NOT resident of ST

    ----------------------------------------------

    If you choose OH as the stateSearch

    and have the following studentFile

    John Smith
    307C Meshell
    Youngstown
    OH
    44555
    Roger Federer
    12 Main St
    Niles
    OH
    44446
    Rafa Nadal
    10 Retire Dr
    Pittsburgh
    PA
    66666
    theDummy

    The output would be

    What state are you looking for?
    OH

    State Report

    John Smith
    307C Meshell
    Youngstown, OH 44555

    Resident of OH

    ---------------------------------------

    Roger Federer
    12 Main St
    Niles, OH 44446

    Resident of OH

    ---------------------------------------

    Rafa Nadal
    10 Retire Dr
    Pittsburgh, PA 66666

    NOT resident of OH
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,087
    Rep Power
    2222
    You need to show us what you've done so far and tell us where you're stuck.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    8
    Rep Power
    0
    Code:
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* Lab 8 Working with classes                                   */
    /*                                                              */
    /* Your name(s) here                                            */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* #includes                                                    */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    #include <iostream>
    #include <iomanip>
    #include <fstream>
    using namespace std;
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* struct Definition for  theInputs                             */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    struct theInputs
    {
    
    char   studentName [20];
    string theAddress;
    string theCity;
    char   stateCode [3];
    int    theZip;
    
    };
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* Class definition for  theStudent                             */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    class theStudent
    {
    
    private:
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* Declare variables global to the class                        */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    fstream studentData;
    
    theInputs penguinPete;
    
    char stateSearch [3];
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* Prototypes for the class methods                             */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    public:
    
    theStudent ();
    
    int  getStudentName ();
    void getRestOfInfo ();
    void displayOutput ();
    void evaluateState ();
    
    };
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* Constructor                                                  */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    theStudent :: theStudent ()
    {
    
    studentData.open ("studentFile", ios :: in);
    
    cout << "What state are you looking for?"
        << endl;
    
    cin.getline (stateSearch, 3, '\n');
    
    cout << "\033[2J\033[H"
         << endl
         << endl
         << "State Report"
         << endl
         << endl;
    
    }
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* Method getStudentName                                        */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    int theStudent :: getStudentName ()
    {
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* Read the student name from the file                          */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    studentData.getline (penguinPete.studentName,20);
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* If the name is not "theDummy" return 1, else return 0        */
    /*                                                              */
    /*--------------------------------------------------------------*/
    cout << penguinPete.studentName << endl;
    
    if (strcmp(penguinPete.studentName, "theDummy")==0 )
    	return 0;
    
    	return 1;
    }
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* Method getRestOfInfo                                         */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    void theStudent :: getRestOfInfo ()
    
    {
    
    char junk [20];
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* Prompts/read for rest of input                               */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    
    }
    
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* Method DisplayOutput                                         */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    void theStudent :: displayOutput ()
    {
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* Display output                                               */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* Produce output                                               */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    
    
    }
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* Method evaluateState                                         */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    void theStudent :: evaluateState ()
    {
    
    
    
    
    }
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* Main module                                                  */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    main ()
    {
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* Main module variables                                        */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    theStudent thePerson;
    
    int thereIsValidStudent;
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* Set screen for proper formatting                             */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    cout << setiosflags (ios :: fixed)
        << setprecision (0);
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* Processing                                                   */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    thereIsValidStudent = thePerson.getStudentName ();
    
    while (thereIsValidStudent)
    
          {
    
          thePerson.getRestOfInfo ();
          thePerson.displayOutput ();
          thePerson.evaluateState ();
    
          thereIsValidStudent = thePerson.getStudentName ();
    
          }
    
    /*--------------------------------------------------------------*/
    /*                                                              */
    /* End                                                          */
    /*                                                              */
    /*--------------------------------------------------------------*/
    
    }

    Okay so after working on it last night, I think I figured out how to get the information from a seperate file onto my strct. I also think I managed to have the program return 1 or 0. Where I am stuck is when the program recognizes that the person within the data is either from Ohio or not from Ohio.

IMN logo majestic logo threadwatch logo seochat tools logo