Joined: 21 Mar 2006 Posts: 172 Location: Knee deep in a c++ book
Posted: Thu Sep 06, 2007 4:49 pm Post subject:
Ok here it is. The best i could make it in my free time.
Code:
/* 09/7/07
Made by losplagos
Please do not give this out without my permission */
#include <iostream>
class CON // I like classes
{
public: //just easyer for me to make the functions public
CON(){}; // My constructor
~CON(){}; // My destructor
void cKilometersMiles(); // Declaring my functions
void cFahrenheitCelsius();
private:
void cMiles(); // im keeping these private so only members of the class can access them.
void cKilometers();
void cFahrenheit();
void cCelsius();
double *cKm;
double *conKm;
int control;
};
void CON::cKilometersMiles()
{
std::cout << "Enter 1 to Convert Kilometers to miles and 2 to Conver miles to kilometers" << std::endl;
std::cin >> control;
switch(control)
{
case 1:
cKilometers();
break;
case 2:
cMiles();
break;
default:
std::cout << "Invalid input" << std::endl;
break;
}
control = 0;
}
void CON::cFahrenheitCelsius()
{
std::cout << "Enter 1 to Convert Fahrenheit to celsius and 2 to Conver celsius to Fahrenheit" << std::endl;
std::cin >> control;
switch(control)
{
case 1:
cFahrenheit();
break;
case 2:
cCelsius();
break;
default:
std::cout << "Invalid input" << std::endl;
break;
}
control = 0;
}
void CON::cMiles()
{
conKm = new double;
cKm = new double;
*conKm = 1.61;
std::cout << "Enter number of miles: ";
std::cin >> *cKm;
*cKm = *conKm * *cKm;
std::cout << "Answer is " << *cKm << " Kilometers" << std::endl;
delete conKm; // Saving memory by deleting i could do this in cKilometers
delete cKm;
conKm=0; // setting the address to 0 so it wont be a wild / stray pointer
cKm=0;
}
void CON::cKilometers()
{
conKm = new double;
cKm = new double;
*conKm = .62;
std::cout << "Enter number of KiloMeters: ";
std::cin >> *cKm;
*cKm = *conKm * *cKm;
std::cout << "Answer is " << *cKm << " Miles" << std::endl;
delete conKm; // Saving memory by deleting
delete cKm;
conKm=0; // setting the address to 0 so it wont be a wild / stray pointer
cKm=0;
}
void CON::cCelsius()
{
conKm = new double;
cKm = new double;
*conKm = 1.8;
std::cout << "Enter number in Celsius: ";
std::cin >> *cKm;
*cKm = (*conKm * *cKm)+32;
std::cout << "Answer is " << *cKm << " Degrees Fahrenheit" << std::endl;
delete conKm; // Saving memory by deleting i could do this in cKilometers
delete cKm;
conKm=0; // setting the address to 0 so it wont be a wild / stray pointer
cKm=0;
}
void CON::cFahrenheit()
{
conKm = new double;
cKm = new double;
*conKm = 1.8;
std::cout << "Enter number in Fahrenheit: ";
std::cin >> *cKm;
*cKm = (*cKm - 32)* *conKm;
std::cout << "Answer is " << *cKm << " Degrees celsius" << std::endl;
delete conKm; // Saving memory by deleting i could do this in cKilometers
delete cKm;
conKm=0; // setting the address to 0 so it wont be a wild / stray pointer
cKm=0;
}
int main()
{
int *si = new int;
CON *D= new CON;
int quit = 1;
do
{
std::cout << " Enter 0 to quit, 1 to mess with distances and 2 to mess with tempatures"<< std::endl;
std::cin >> *si;
switch(*si)
{
case 0:
quit = 0;
break;
case 1:
D->cKilometersMiles();
break;
case 2:
D->cFahrenheitCelsius();
break;
default:
std::cout << "ERROR INVALID INPUT";
}
} while (quit==1);
delete si;
delete D;
quit = 0;
si = 0;
D = 0;
}
The Extension 'rar' was deactivated by an board admin, therefore this Attachment is not displayed.
All times are GMT - 6 Hours Goto page Previous1, 2
Page 2 of 2
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum