Classes–A Deeper look

/*  Filename: Student.h    */


class Student{

	//these are private by default
	int cbNo;
	char name[10];
	int total;
	char status;

	char getGrade(); //get grade
	void getInfo(); //display student info
	char getStatus(); //return P or F
	void setTotal(int);

	Student(int, char []); //parameterised constructor


/*  Filename: Student.cpp  */

#include "Student.h"

using namespace std;


Student::Student(){ //<which class>:: <which function>
	strcpy_s(name, ""); //cant copy a string to another;


Student::Student(int cb, char n[]){
	cbNo = cb;
	strcpy_s(name, n); 

char Student::getGrade(){
	char grade;

	if(total >80){
		grade = 'A';
		status = 'P';
	} else if(total >70){
		grade = 'B';
		status = 'P';
	} else {
		grade = 'C';
		status = 'F';
	return grade;

void Student::getInfo(){
	cout<<"CB:"<< cbNo<<endl;
	cout<<"Name: "<<name<<endl;
	cout<<"Grade: " << getGrade()<<endl;
	cout<<"Status: " <<getStatus()<<endl;
char Student::getStatus(){
	return status;

void Student::setTotal(int t){
	total = t;

int main(){

	Student std(3403, "Praveen");

	Student s;

	return 0;


About praveenaj

I'm just an average guy who enjoys doing Programming/Web Designs/Pencil art & drinking coffee :)
This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s