Skip to content

Instantly share code, notes, and snippets.

@tywoplenty
Created March 4, 2015 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tywoplenty/6d11f65226d827b7c22f to your computer and use it in GitHub Desktop.
Save tywoplenty/6d11f65226d827b7c22f to your computer and use it in GitHub Desktop.
convert from one unit to another.
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="calculator" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/calculator" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/calculator" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
<Add option="-fexceptions" />
</Compiler>
<Unit filename="main.cpp" />
<Extensions>
<code_completion />
<envvars />
<debugger />
</Extensions>
</Project>
</CodeBlocks_project_file>
# depslib dependency file v1.0
1420478916 source:c:\users\taiwo\desktop\grading program\calculator\main.cpp
<iostream>
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<ActiveTarget name="Debug" />
<File name="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1844" topLine="0" />
</Cursor>
<Folding>
<Collapse line="4" />
<Collapse line="9" />
<Collapse line="43" />
<Collapse line="45" />
<Collapse line="78" />
<Collapse line="99" />
</Folding>
</File>
</CodeBlocks_layout_file>
#include <iostream>
using namespace std;
class Measure{
double m_value;
double centimeter, meter, feet, inch;
int unit;
public:
Measure(double &val, int &un):m_value(val), unit(un) {
switch(unit){
case 1:
meter = m_value;
centimeter = meter * 100;
inch = centimeter / 2.54;
feet = inch /12;
break;
case 2:
centimeter = m_value;
meter = centimeter/100;
inch = centimeter / 2.54;
feet = inch /12;
break;
case 3:
inch = m_value;
centimeter = inch * 2.54;
meter = centimeter * 100;
feet = inch /12;
break;
case 4:
feet = m_value;
inch = feet * 12;
centimeter = inch * 2.54;
meter = centimeter * 100;
break;
default:
break;
}
}
void print();
};
void Measure::print(){
switch (unit) {
case 1:
cout <<m_value << " meter(s) is equal to:\n"
<< centimeter <<" centimeters\n"
<< inch <<" inches\n"
<< feet <<" feets\n";
break;
case 2:
cout <<m_value << " centimeter(s) is equal to:\n"
<< meter <<" meter(s)\n"
<< inch <<" inche(s)\n"
<< feet <<" feet(s)\n";
break;
case 3:
cout <<m_value << " inch(s) is equal to:\n"
<< feet <<" feet(s)\n"
<< centimeter <<" centimeter(s)\n"
<< meter <<" meter(s)\n";
break;
case 4:
cout <<m_value << " feets(s) is equal to:\n"
<< inch <<" inch(s)\n"
<< centimeter <<" centimeter(s)\n"
<< meter <<" meter(s)\n";
break;
}
}
void takeunit(int &unit);
int main()
{
double value;
int unit;
takeunit(unit);
do{
if (unit>0 && unit <5) {
cout << "Enter Value" << endl;
cin >> value;
Measure neew(value,unit);
neew.print();
takeunit(unit);
}
else {
cout << "Invalid Unit choice.";
takeunit(unit);
}
}while (unit!=0);
}
void takeunit(int &unit) {
cout << "Convert from:\n1 - Meters.\n2 - Centimeters.\n3 - Inches.\n4 - Feets." << endl;
cin >> unit;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment