Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > Visual C++
|
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 October 25th, 2008, 04:20 PM
Authorized User
 
Join Date: Apr 2008
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default Class to set student name & id

Hi GUys,
I have created a class to set the student name & class id. But the student id don't let me compile becase it is an integer.
Can someome help me to fix it please ?
Thanks,
My code is below for your attention:

// Class header

#include <string>
using namespace std;

class student3
{
private:
    string name;
    int id;

public:
        // transformer methods
        void setname( string );
        void setid( int );

        // accessor methods
        string getname();
        int getid();
};

#include "student3.h"

void student3::setname( string myname )
{
    name = myname;
}

void student3::setid( int myid )
{
    id = myid;
}

string student3::getname()
{
    return name;
}

int student3::getid()
{
    return id;
}

#include <iostream>
#include "student3.h"

using namespace std;

main()
{
    string nm;
    int id;
    student3 stud1, stud2;

    cout << "Please enter name " << endl;
    cin >> nm;
    stud1.setname( nm );

    cout << "Please enter id " << endl;
    cin >> id;
    stud1.setid( id );

    cout << "The name of the first student is " << stud1.getname() << endl;
    cout << "The id of the first student is " << stud1.getid() << endl;

    system( "pause" );
}

 
Old December 24th, 2008, 01:12 PM
Friend of Wrox
 
Join Date: Mar 2008
Posts: 133
Thanks: 15
Thanked 1 Time in 1 Post
Send a message via ICQ to iceman90289 Send a message via AIM to iceman90289
Default

i threw this code into dev C++ and it worked just fine.

whats the error you are getting?
 
Old February 3rd, 2009, 01:54 PM
Authorized User
 
Join Date: Apr 2008
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Many thanks for your attention,
It is working fine now





Similar Threads
Thread Thread Starter Forum Replies Last Post
The class is configured to run as a security ID di marko2748au Pro VB Databases 2 January 20th, 2011 11:42 PM
Condition to set a unique ID between 2 btns onClic ismailc XSLT 0 August 18th, 2008 09:04 AM
MFC Class wizard & vc++ 6 & message mapping C@uark Visual C++ 0 February 20th, 2007 06:47 PM
'this.ID = id;' in class construction holf BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 October 6th, 2006 10:58 AM
XSLT change class attribute by ID? matallen XSLT 8 March 1st, 2006 05:00 PM





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