Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- using namespace std;
- class Student {
- private:
- int id;
- string name;
- public:
- Student(int i = 0, string n = "none");
- Student(int i, string n);
- int getId();
- string getName();
- void setId(int newId);
- void setName(string newName);
- void printData();
- };
- Student::Student(int i = 0, string n = "none")
- {
- id = i;
- name = n;
- }
- Student::Student(int i, string n)
- {
- id = i;
- name = n;
- }
- int Student::getId()
- {
- return id;
- }
- void Student::setId(int newId)
- {
- if (newId < 0)
- {
- id = 0;
- }
- else
- {
- id = newId;
- }
- }
- string Student::getName()
- {
- return name;
- }
- void Student::setName(string newName)
- {
- name = newName;
- }
- void Student::printData()
- {
- cout << "ID: " << id << endl;
- cout << "Name: " << name << endl;
- }
- //////////////////////////
- // client code
- ////////////////////////
- int main() {
- Student s1;
- Student s2(2, "Heather");
- Student s3;
- s1.setName("James");
- s1.setId(1);
- s1.printData();
- s2.printData();
- s3.printData();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement