Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- / Aaron Smith - Code Review Example
- #include <iostream>
- #include <string
- #pragma warning( disable : 4244)
- class TestResults
- {
- public:
- static TestResults* CreateTestResultsBasedOnAttitude(int const attitude)
- {
- TestResults newGrades;
- switch (attitude)
- {
- case 0:
- newGrades.m_TotalPercent = 98.0f;
- break;
- case 1:
- newGrades.m_TotalPercent = 5.0f;
- break;
- case 2:
- newGrades.m_TotalPercent = 45.0f;
- case 3:
- newGrades.m_TotalPercent = 70.0f;
- break;
- default:
- newGrades.m_TotalPercent = -1;
- break;
- }
- return &newGrades;
- }
- uint16_t getTotalPercent() { return m_TotalPercent; }
- uint16_t m_TotalPercent;
- };
- class Person
- {
- public:
- class Person(char* name, int age)
- {
- m_Age = age;
- }
- ~Person() { }
- char* GetName() {
- return m_Name;
- }
- void SetName(char* name)
- {
- int SIZEOFNAME = strlen(name);
- memcpy(m_Name, name, SIZEOFNAME + 1);
- }
- void SetAge(int const age) const
- {
- m_Age = age;
- }
- private:
- static int const MAXCHARS = 11;
- char m_Name[MAXCHARS];
- int m_Age;
- };
- class Student : public Person
- {
- public:
- Student() {}
- Student(char* name, int age)
- : Person(name,age)
- {
- }
- ~Student() { }
- float GetTestResults() const
- {
- return m_TestResults->getTotalPercent();
- }
- void SetTestResults(TestResults* TestResults)
- {
- m_TestResults = TestResults;
- }
- private:
- TestResults* m_TestResults;;
- };
- int main()
- {
- //create a m_Person called aaron smith who is 28 and take a test while happy
- Student* m_Person1 = new Student("Aaron Smith", 28);
- m_Person1->SetTestResults(TestResults::CreateTestResultsBasedOnAttitude(5));
- std::cout << m_Person1->GetName() << " is " << m_Person1->m_Age << " and Scored " << m_Person1->GetTestResults() <<std::endl;
- delete m_Person1;
- //now lets reuse m_Person and change the name,age and take the test while angry
- Student* m_Person2 = new Student;
- m_Person2->SetName("Captain America The Third");
- m_Person2->SetAge(800);
- m_Person2->SetTestResults(TestResults::CreateTestResultsBasedOnAttitude(2));
- std::cout << m_Person2->GetName() << " is " << m_Person2->m_Age << " and Scored " << m_Person1->GetTestResults();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement