Classes–A Deeper look


/*********************/
/*  Filename: Student.h    */
/*********************/


/*-------prototypes-------*/

class Student{

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

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

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

};

/*********************/
/*  Filename: Student.cpp  */
/*********************/

#include<iostream>
#include<string>
#include "Student.h"

using namespace std;

/*-------implementations--------*/

Student::Student(){ //<which class>:: <which function>
	cbNo=0;
	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");
	std.setTotal(90);
	std.getInfo();

	Student s;
	s.getInfo();

	system("pause");
	return 0;

}
Advertisements

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:

WordPress.com Logo

You are commenting using your WordPress.com 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