Skip to content

Instantly share code, notes, and snippets.

@mhassanist
Last active January 13, 2021 07:59
Show Gist options
  • Save mhassanist/8565e681e530d0f1ecf4febde931a2a1 to your computer and use it in GitHub Desktop.
Save mhassanist/8565e681e530d0f1ecf4febde931a2a1 to your computer and use it in GitHub Desktop.
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include <string>
using namespace std;
#include<iostream>
using namespace std;
class Student
{
string name;
int id;
int gradDate;
public:
Student(): Student("",0,1990){};// Student s1;
Student(string idIn){} // Student s2(151);
Student(string nameIn, int idIn, int gradDateIn){ //
name = nameIn;
id = idIn;
gradDate = gradDateIn;
}
void setName(string nameIn);
void setId(int idIn);
void setGradDate(int dateIn);
string getName();
int getId();
int getGradDate();
void print();
};
void Student::setName(string nameIn)
{
name = nameIn;
}
void Student::setId(int idIn)
{
id = idIn;
}
void Student::setGradDate(int gradDateIn)
{
gradDate = gradDateIn;
}
void Student::print()
{
cout<<name<<" "<<id<<" "<<gradDate;
}
string Student::getName()
{
return name;
}
int Student::getId()
{
return id;
}
int Student::getGradDate()
{
return gradDate;
}
int main()
{
/*Student student1;
student1.setName("Catherine Gamboa"); //assign a value to the student name
student1.setId(54345); //assign a value to the student id number
student1.setGradDate(2017); //assign a value to the student grad date
*/
Student student1("Ahmed", 1515, 2002);
cout<<"Using the student access functions\n";
cout<<"Student1 name = "<<student1.getName()<<"\n";
cout<<"Student1 ID = "<<student1.getId()<<"\n";
cout<<"Student1 Grad Date = "<<student1.getGradDate()<<"\n";
Student student2("Ahmed2", 1414, 2001);
cout<<"Using the student access functions\n";
cout<<"Student1 name = "<<student2.getName()<<"\n";
cout<<"Student1 ID = "<<student2.getId()<<"\n";
cout<<"Student1 Grad Date = "<<student2.getGradDate()<<"\n";
int id;
Student s3;
//ask the user to enter
cout<<"Enter student id: " ;
cin>>id;
s3.setId(id);
cout<<"The id you entered is: " << s3.getId();
cout<<"The year from the construtor initialization: " << s3.getGradDate();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment