Skip to content

Instantly share code, notes, and snippets.

@Jeffrey-Kimani
Created June 15, 2016 11:06
Show Gist options
  • Save Jeffrey-Kimani/0eb9b48ab2843a7f779cb9f0dc30678a to your computer and use it in GitHub Desktop.
Save Jeffrey-Kimani/0eb9b48ab2843a7f779cb9f0dc30678a to your computer and use it in GitHub Desktop.
Exercise 2.... Calculating cat 1 and cat 2 and printing the total averrage and grade
<?xml version="1.0" encoding="UTF-8"?>
<module type="CPP_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/main.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/CMakeLists.txt" isTestSource="false" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library name="Header Search Paths">
<CLASSES>
<root url="file://C:/Program Files (x86)/CodeBlocks/MinGW/lib/gcc/mingw32/4.8.1/include" />
<root url="file://C:/Program Files (x86)/CodeBlocks/MinGW/lib/gcc/mingw32/4.8.1/include-fixed" />
<root url="file://C:/Program Files (x86)/CodeBlocks/MinGW/include" />
</CLASSES>
<SOURCES>
<root url="file://C:/Program Files (x86)/CodeBlocks/MinGW/lib/gcc/mingw32/4.8.1/include" />
<root url="file://C:/Program Files (x86)/CodeBlocks/MinGW/lib/gcc/mingw32/4.8.1/include-fixed" />
<root url="file://C:/Program Files (x86)/CodeBlocks/MinGW/include" />
</SOURCES>
</library>
</orderEntry>
</component>
</module>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
<component name="CidrRootsConfiguration">
<sourceRoots />
<libraryRoots />
<excludeRoots />
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
<OptionsSetting value="true" id="Add" />
<OptionsSetting value="true" id="Remove" />
<OptionsSetting value="true" id="Checkout" />
<OptionsSetting value="true" id="Update" />
<OptionsSetting value="true" id="Status" />
<OptionsSetting value="true" id="Edit" />
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Exercise2.iml" filepath="$PROJECT_DIR$/.idea/Exercise2.iml" />
</modules>
</component>
</project>
cmake_minimum_required(VERSION 3.5)
project(Exercise2)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(Exercise2 ${SOURCE_FILES})
#include <iostream>
#include <iomanip>
using namespace std;
class Student
{
private:
string name,course;
int cat1,cat2;
double GetTotalCat()
{
return (double) cat1 + cat2;
}
double GetAverage()
{
return GetTotalCat()/2;
}
char GetGrade()
{
double Average = GetAverage();
if(Average>=70)
{
return 'A';
}
else if(Average <= 69 && Average >=60)
{
return 'B';
}
else if(Average <= 59 && Average >=50)
{
return 'C';
}
else if(Average <= 49 && Average >=40)
{
return 'D';
}
else
{
return 'E';
}
}
public:
Student(string name,string course,int cat1,int cat2)
{
this->cat1 = cat1;
this->cat2 = cat2;
this->name = name;
this->course = course;
}
void PrintResultSlip()
{
cout<<"\n";
cout<<"Name:"<<setw(5)<<name<<endl;
cout<<"Course:"<<setw(3)<<course<<endl;
cout<<"-------------------------------------------"<<endl;
cout<<"Cat1:"<<setw(5)<<cat1<<" Marks"<<endl;
cout<<"Cat2:"<<setw(5)<<cat2<<" Marks"<<endl;
cout<<"-------------------------------------------"<<endl;
cout<<"Total:"<<setw(4)<<GetTotalCat()<<" Marks"<<endl;
cout<<"Averrage"<<setw(3)<<GetAverage()<<" Marks"<<endl;
cout<<"-------------------------------------------"<<endl;
cout<<"Grade:"<<setw(5)<<GetGrade()<<endl;
}
};
int main() {
string name,course;
int cat1,cat2;
cout<<"Enter the Students Name: ";
cin>>name;
cout<<"Enter the Students Course: ";
cin>>course;
cout<<"Enter the Students Cat1 Marks: ";
cin>>cat1;
cout<<"Enter the Students Cat2 Marks: ";
cin>>cat2;
Student student1(name,course,cat1,cat2);
student1.PrintResultSlip();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment