DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Beginner-Brad Guest

    A COMPLETED PROGRAM


    /**********************************************************************/
    /* Program Name: Video2.cpp (Assignment # 1) */
    /* Program Purpose: Use SETTERS & GETTERS to interact with object */
    /* File Name: Assignment1VIDEO */
    /* Programmer's Name: Brad Isaacs */
    /* Revision History: Assignment # 1 */
    /**********************************************************************/

    /**********************************************************************/
    /* Class Name: Video.h file */
    /* Class Purpose: Create a class that models an actual video in */
    /* a store. */

    /* Revision History: Assignment # 1 */
    /**********************************************************************/

    /**********************************************************************/
    /* */
    /* Name: SET&GET the Video class */
    /* Purpose: Use SETTERS & GETTERS functions to display the */
    /* video's information. */
    /* Parameters: strings, int and char pointers reference */
    /* History */
    /* Version 1.0 - 00/10/28 */
    /* Assignment # 1 - Use Setters & Getters */
    /**********************************************************************/

    //Video.h Header file
    //header file for Video -- contains class declarations


    #ifndef VIDEO_H
    #define VIDEO_H
    #include <iostream> //for cin,cout,new and delete
    #include <string> //for character strings and for strncpy()

    using namespace std;

    #define MEMBERSHIPNUMBER_MAX_SIZE 10 //allocates 9 + null char
    #define RETURNDATE_MAX_SIZE 10 //allocates 9 + null char

    class Video //Video class definition
    {
    private: //Declare Private data member
    string FilmName; //Define data types
    string Distributor;
    string Director;
    int Year;
    int NumberCopies;
    int CurrentShelf;
    char MembershipNumber[MEMBERSHIPNUMBER_MAX_SIZE];
    char ReturnDate[RETURNDATE_MAX_SIZE];
    int NumberActualRentals;
    public: //Declare public constructor
    Video(); //Default constructor
    ~Video(); //destructor


    const string& get_FilmName() const; //get filmname
    void set_FilmName(const string& FName); //set filmname
    const string& get_Distributor() const; //get distributor
    void set_Distributor(const string& Dist); //set distributor
    const string& get_Director() const; //get director
    void set_Director(const string& Direc); //set director
    int get_Year() const; //get year
    void set_Year(int Yr); //set year
    int get_NumberCopies() const; //get number of copies
    void set_NumberCopies(int NumCop); //set num copies
    int get_CurrentShelf() const; //get current shelf
    void set_CurrentShelf(int CurShelf); //set current shelf
    const char *get_MembershipNumber() const; //declare a constant char
    of pointer
    //type, constant function
    as well.
    //changes are prohibited
    void set_MembershipNumber(const char *MemNum);//the char of pointer type
    MemNum
    //changes are prohibited.
    const char *get_ReturnDate() const; //declare a constant char
    of pointer
    //type, constant function
    as well.
    //changes are prohibited
    void set_ReturnDate(const char *ReDate); //the char of pointer type
    ReDate
    //changes are prohibited.
    int get_NumberActualRentals() const; //get number actual rentals
    void set_NumberActualRentals(int NumRentals); //set number actual rentals

    };
    #endif
    //Video1.cpp Implementation file
    //contains class data and member function definitions

    #include "Video.h" //include class declarations
    #include <string> //for strncpy() and character strings
    #include <iostream> //for cin, cout


    Video::Video() //constructor
    {}

    Video::~Video() //destructor
    {}

    const string& Video::get_FilmName() const
    {
    return FilmName;
    }
    void Video::set_FilmName(const string& FName)
    {
    FilmName = FName;
    }
    const string& Video::get_Distributor() const
    {
    return Distributor;
    }
    void Video::set_Distributor(const string& Dist)
    {
    Distributor = Dist;
    }
    const string& Video::get_Director() const
    {
    return Director;
    }
    void Video::set_Director(const string& Direc)
    {
    Director = Direc;
    }
    int Video::get_Year() const
    {
    return Year;
    }
    void Video::set_Year(int Yr)
    {
    Year = Yr;
    }
    int Video::get_NumberCopies() const
    {
    return NumberCopies;
    }
    void Video::set_NumberCopies(int NumCop)
    {
    NumberCopies = NumCop;
    }
    int Video::get_CurrentShelf() const
    {
    return CurrentShelf;
    }
    void Video::set_CurrentShelf(int CurShelf)
    {
    CurrentShelf = CurShelf;
    }
    const char *Video::get_MembershipNumber() const
    {
    return MembershipNumber;
    }
    void Video::set_MembershipNumber(const char *MemNum)
    {
    strncpy(MembershipNumber, MemNum,sizeof(MembershipNumber)-1);
    }
    const char *Video::get_ReturnDate() const
    {
    return ReturnDate;
    }
    void Video::set_ReturnDate(const char *ReDate)
    {
    strncpy(ReturnDate, ReDate, sizeof(ReturnDate)-1);
    }
    int Video::get_NumberActualRentals() const
    {
    return NumberActualRentals;
    }
    void Video::set_NumberActualRentals(int NumRentals)
    {
    NumberActualRentals = NumRentals;
    }

    //Main Video2.cpp file

    #include "Video.h" //include video header file
    #include <iostream> //for cin,cout,new and delete
    #include <string> //for character strings and for strncpy()
    #include <conio.h> //for getch()
    #include <process.h> //for exit()
    using namespace std;


    void main()
    {

    int iUserKey;
    cout << "\n****************** MOVIE LAND CENTRAL*******************\n";
    cout << "\n--------------------------------------------------------\n";
    cout << "\n\tPlease select 1 for the video information.\n";
    cout << "\n\tAll other keys on the keyboard to exit the program.\n";
    cout << "\n--------------------------------------------------------\n";


    iUserKey = getch(); //getch() does not echoe character to the screen
    iUserKey = iUserKey - 48;//Takes what user presses(-48 ASCII coded)
    if(iUserKey == 1) //If iUserKey equals 1(ASCII code 49-48=1)
    { //diplay video information to the screen.

    Video Info;
    Info.set_FilmName("Hurricane.");
    cout << "The name of the film is " << Info.get_FilmName() << endl;
    Info.set_Distributor("Universal Pictures.");
    cout << "The name of the distributor is " << Info.get_Distributor()
    << endl;
    Info.set_Director("Johnny Bloomberg.");
    cout << "The name of the director is " << Info.get_Director() << endl;
    Info.set_Year(2000);
    cout << "The year for this film was " << Info.get_Year() << "." << endl;
    Info.set_NumberCopies(15);
    cout << "The number of copies available are " << Info.get_NumberCopies()
    << "." << endl;
    Info.set_CurrentShelf(12);
    cout << "The number of copies currently on the shelf are " << Info.get_CurrentShelf()
    << "." << endl;
    Info.set_MembershipNumber("65134990");
    cout << "Your membership number is " << Info.get_MembershipNumber()
    << "." << endl;
    Info.set_ReturnDate("00/11/8");
    cout << "Your return date is " << Info.get_ReturnDate() << "." << endl;
    Info.set_NumberActualRentals(3);
    cout << "The number of actual rentals for this film is " << Info.get_NumberActualRentals()
    << "." << endl;
    cout << "\n--------------------------------------------------------\n";


    }
    else //otherwise,
    {
    exit(0); //exit the program
    }



    }












  2. #2
    Steve Wade Guest

    Re: A COMPLETED PROGRAM

    You still need to initialise your class members in your constructor. I
    interview for junior programmer positions and if I saw this, I would fail
    the candidate. It is very bad practice.

    Steve

    "Beginner-Brad" <bradhouse@sprint.ca> wrote in message
    news:39fc6427$1@news.devx.com...
    >
    > /**********************************************************************/
    > /* Program Name: Video2.cpp (Assignment # 1) */
    > /* Program Purpose: Use SETTERS & GETTERS to interact with object */
    > /* File Name: Assignment1VIDEO */
    > /* Programmer's Name: Brad Isaacs */
    > /* Revision History: Assignment # 1 */
    > /**********************************************************************/
    >
    > /**********************************************************************/
    > /* Class Name: Video.h file */
    > /* Class Purpose: Create a class that models an actual video in */
    > /* a store. */
    >
    > /* Revision History: Assignment # 1 */
    > /**********************************************************************/
    >
    > /**********************************************************************/
    > /* */
    > /* Name: SET&GET the Video class */
    > /* Purpose: Use SETTERS & GETTERS functions to display the */
    > /* video's information. */
    > /* Parameters: strings, int and char pointers reference */
    > /* History */
    > /* Version 1.0 - 00/10/28 */
    > /* Assignment # 1 - Use Setters & Getters */
    > /**********************************************************************/
    >
    > //Video.h Header file
    > //header file for Video -- contains class declarations
    >
    >
    > #ifndef VIDEO_H
    > #define VIDEO_H
    > #include <iostream> //for cin,cout,new and delete
    > #include <string> //for character strings and for strncpy()
    >
    > using namespace std;
    >
    > #define MEMBERSHIPNUMBER_MAX_SIZE 10 //allocates 9 + null char
    > #define RETURNDATE_MAX_SIZE 10 //allocates 9 + null char
    >
    > class Video //Video class definition
    > {
    > private: //Declare Private data member
    > string FilmName; //Define data types
    > string Distributor;
    > string Director;
    > int Year;
    > int NumberCopies;
    > int CurrentShelf;
    > char MembershipNumber[MEMBERSHIPNUMBER_MAX_SIZE];
    > char ReturnDate[RETURNDATE_MAX_SIZE];
    > int NumberActualRentals;
    > public: //Declare public constructor
    > Video(); //Default constructor
    > ~Video(); //destructor
    >
    >
    > const string& get_FilmName() const; //get filmname
    > void set_FilmName(const string& FName); //set filmname
    > const string& get_Distributor() const; //get distributor
    > void set_Distributor(const string& Dist); //set distributor
    > const string& get_Director() const; //get director
    > void set_Director(const string& Direc); //set director
    > int get_Year() const; //get year
    > void set_Year(int Yr); //set year
    > int get_NumberCopies() const; //get number of copies
    > void set_NumberCopies(int NumCop); //set num copies
    > int get_CurrentShelf() const; //get current shelf
    > void set_CurrentShelf(int CurShelf); //set current shelf
    > const char *get_MembershipNumber() const; //declare a constant

    char
    > of pointer
    > //type, constant function
    > as well.
    > //changes are prohibited
    > void set_MembershipNumber(const char *MemNum);//the char of pointer

    type
    > MemNum
    > //changes are prohibited.
    > const char *get_ReturnDate() const; //declare a constant

    char
    > of pointer
    > //type, constant function
    > as well.
    > //changes are prohibited
    > void set_ReturnDate(const char *ReDate); //the char of pointer type
    > ReDate
    > //changes are

    prohibited.
    > int get_NumberActualRentals() const; //get number actual rentals
    > void set_NumberActualRentals(int NumRentals); //set number actual rentals
    >
    > };
    > #endif
    > //Video1.cpp Implementation file
    > //contains class data and member function definitions
    >
    > #include "Video.h" //include class declarations
    > #include <string> //for strncpy() and character strings
    > #include <iostream> //for cin, cout
    >
    >
    > Video::Video() //constructor
    > {}
    >
    > Video::~Video() //destructor
    > {}
    >
    > const string& Video::get_FilmName() const
    > {
    > return FilmName;
    > }
    > void Video::set_FilmName(const string& FName)
    > {
    > FilmName = FName;
    > }
    > const string& Video::get_Distributor() const
    > {
    > return Distributor;
    > }
    > void Video::set_Distributor(const string& Dist)
    > {
    > Distributor = Dist;
    > }
    > const string& Video::get_Director() const
    > {
    > return Director;
    > }
    > void Video::set_Director(const string& Direc)
    > {
    > Director = Direc;
    > }
    > int Video::get_Year() const
    > {
    > return Year;
    > }
    > void Video::set_Year(int Yr)
    > {
    > Year = Yr;
    > }
    > int Video::get_NumberCopies() const
    > {
    > return NumberCopies;
    > }
    > void Video::set_NumberCopies(int NumCop)
    > {
    > NumberCopies = NumCop;
    > }
    > int Video::get_CurrentShelf() const
    > {
    > return CurrentShelf;
    > }
    > void Video::set_CurrentShelf(int CurShelf)
    > {
    > CurrentShelf = CurShelf;
    > }
    > const char *Video::get_MembershipNumber() const
    > {
    > return MembershipNumber;
    > }
    > void Video::set_MembershipNumber(const char *MemNum)
    > {
    > strncpy(MembershipNumber, MemNum,sizeof(MembershipNumber)-1);
    > }
    > const char *Video::get_ReturnDate() const
    > {
    > return ReturnDate;
    > }
    > void Video::set_ReturnDate(const char *ReDate)
    > {
    > strncpy(ReturnDate, ReDate, sizeof(ReturnDate)-1);
    > }
    > int Video::get_NumberActualRentals() const
    > {
    > return NumberActualRentals;
    > }
    > void Video::set_NumberActualRentals(int NumRentals)
    > {
    > NumberActualRentals = NumRentals;
    > }
    >
    > //Main Video2.cpp file
    >
    > #include "Video.h" //include video header file
    > #include <iostream> //for cin,cout,new and delete
    > #include <string> //for character strings and for strncpy()
    > #include <conio.h> //for getch()
    > #include <process.h> //for exit()
    > using namespace std;
    >
    >
    > void main()
    > {
    >
    > int iUserKey;
    > cout << "\n****************** MOVIE LAND CENTRAL*******************\n";
    > cout << "\n--------------------------------------------------------\n";
    > cout << "\n\tPlease select 1 for the video information.\n";
    > cout << "\n\tAll other keys on the keyboard to exit the program.\n";
    > cout << "\n--------------------------------------------------------\n";
    >
    >
    > iUserKey = getch(); //getch() does not echoe character to the

    screen
    > iUserKey = iUserKey - 48;//Takes what user presses(-48 ASCII coded)
    > if(iUserKey == 1) //If iUserKey equals 1(ASCII code 49-48=1)
    > { //diplay video information to the screen.
    >
    > Video Info;
    > Info.set_FilmName("Hurricane.");
    > cout << "The name of the film is " << Info.get_FilmName() <<

    endl;
    > Info.set_Distributor("Universal Pictures.");
    > cout << "The name of the distributor is " <<

    Info.get_Distributor()
    > << endl;
    > Info.set_Director("Johnny Bloomberg.");
    > cout << "The name of the director is " << Info.get_Director() << endl;
    > Info.set_Year(2000);
    > cout << "The year for this film was " << Info.get_Year() << "." << endl;
    > Info.set_NumberCopies(15);
    > cout << "The number of copies available are " << Info.get_NumberCopies()
    > << "." << endl;
    > Info.set_CurrentShelf(12);
    > cout << "The number of copies currently on the shelf are " <<

    Info.get_CurrentShelf()
    > << "." << endl;
    > Info.set_MembershipNumber("65134990");
    > cout << "Your membership number is " <<

    Info.get_MembershipNumber()
    > << "." << endl;
    > Info.set_ReturnDate("00/11/8");
    > cout << "Your return date is " << Info.get_ReturnDate() << "." << endl;
    > Info.set_NumberActualRentals(3);
    > cout << "The number of actual rentals for this film is " <<

    Info.get_NumberActualRentals()
    > << "." << endl;
    > cout <<

    "\n--------------------------------------------------------\n";
    >
    >
    > }
    > else //otherwise,
    > {
    > exit(0); //exit the program
    > }
    >
    >
    >
    > }
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >




Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links