Wrox Programmer Forums
|
Visual C++ Questions specific to Microsoft's Visual C++. For questions not specific to this Microsoft version, use the C++ Programming forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual C++ section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 12th, 2005, 01:49 PM
Registered User
 
Join Date: Dec 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default set validation

i have written a class and some code. my next thing to do is put in validation. here is what i have to do:

Modify your StudentGrade class such that the "set" methods perform data validation. A student ID should be in the range of 10000-50000, and a grade should be in the range 0 - 100. Use a single "if" statement (using the && operator) in each "set" method.

Here is my code:

#include <iostream>
    using std::cout;
    using std::cin;
    using std::endl;

    #include <string>
    using std::string;
    using std::getline;

    class StudentGrade
  {
    public:
    //function that sets the student ID
    void setStudentID( string number )
    {
        studentID = number; //store the course name in the object
    }

    //function that gets the student ID
    string getStudentID()
    {
        return studentID; //returns the objects Student ID
    }

    void setTestScore( string score )
    {
        testScore = score;
    }

    string getTestScore()
    {
        return testScore;
    }

    void displayMessage()
    {
        cout << "Student " << getStudentID() << " has a score of " << getTestScore() << endl;
    }
    private:
    string studentID;
    string testScore;
};

    int main()
   {
    string studentIDnumber;
    string studentTestscore;
    StudentGrade myStudentID;


    cout << "Student ID is: " <<myStudentID.getStudentID() << endl;

    cout << "\nPlease enter the Student ID number:" << endl;
    getline( cin, studentIDnumber );
    myStudentID.setStudentID( studentIDnumber );

    cout << endl;

    cout << "Student test score is: " <<myStudentID.getTestScore() << endl;

    cout << "\nPlease enter the Student Test Score:" << endl;
    getline( cin, studentTestscore );
    myStudentID.setTestScore( studentTestscore );

    cout << endl;

    myStudentID.displayMessage();
    return 0;
   }
every time i try and put in the data validation and the if statement it crashes the program. what am i doing wrong? how do i put in the data validation?






Similar Threads
Thread Thread Starter Forum Replies Last Post
Standalone validation + web form validation morbo Struts 0 August 19th, 2008 04:02 AM
XPath: set operation with a disjoint node set rich_unger XSLT 7 May 6th, 2008 09:24 AM
Validation using Validation Framework kalyangvd Struts 1 January 2nd, 2008 06:53 AM
how i set charcter set to a connection yoord BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 April 23rd, 2005 07:47 AM
How to set DOM character set sonicDace XML 0 May 27th, 2004 08:52 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.