Steemit Learning Club S23W1: I will create a mini project with a C++ program to convert currency, temperature, and measure.
Steemian Friends,
Today, I will participate in the Technology and development club of @mohammadfaisal, @kafio, and @alejos7ven, sirs of Steemit Learning Club S23W1. Today, I will create a mini project with a C++ program to convert currency, temperature, and measure. I can practice my C++ programs by participating in the tech club and learning more by taking advice from mentors. I hope everyone will help me learn programming.
Design By Canva
Today, I will show you a small project with one of my favourite programming languages (C++). I will show currency and temperature conversion and measure conversion using a C++ program. I love writing C++ programs. Although I am an electrical engineer, I still love to learn to program. I get an opportunity to practice programming language through learning the challenges of the Steemit platform. Below is the simple technique of creating the program that users can learn by watching.
I first declared the header file of the C++ program. This file is called a library file and holds declarations of functions and classes used in the program. At the beginning of writing a C++ program, the header file must be written. I have declared the header file of my written program below.
#include < iostream>
Then, I used the namespace std: to avoid using std:: for cout and cin. So, I wrote the namespace after writing the header file of my program.
using namespace std;
Then, I wrote the comment section in between writing the program. I explained the program's workings through comments. Read my program comments to get an idea about the program. The method of writing comments is given below.
// Currency conversion (money to USD)
// Temparature conversion (Celsius to fahrenheit)
// Length conversion (Meter to feet)
Then, I declared the main function and variables of the C++ program. My program will do the conversion in three parts. So, I declared a function and variable for the money conversion. Then, I declared the function and variable for the temperature conversion. Then, I declared the function and variable to convert the third measurement. Below, I have shown three parts of function and variable declaration.
I have used double variables in each section because the value of money, temperature, and measurement can be decimal. 1 USD = 130 taka (local) of our country has been inputted to convert.
Then, complete the conversion using the USD = bdt/130 formula and print the result with cout.
Then, I declared a double variable to convert from Celsius to Fahrenheit and output the Fahrenheit using the formula Fahrenheit = (Celsius * 9/5)+32. I expressed the result through cout.
Similarly, by declaring a double variable, we use the formula feet = meter*3.28 to convert the measurement and express the result with cout. Here, take 1 meter = 3.28 feet.
Currency Conversion:
void currencyConverter() {
double bdt, usd;
cout << "Write money: ";
cin >> bdt;
usd = bdt / 130; // Let's say 1 dollar = 130 Taka
cout << "Dollar Conversion: $" << usd << endl;
}
Temperature Conversion:
void temperatureConverter() {
double celsius, fahrenheit;
cout << "Write the celsius Temparature: ";
cin >> celsius;
fahrenheit = (celsius * 9/5) + 32;
cout << "fahrenheit conversion: " << fahrenheit << "°F" << endl;
}
length Conversion:
void lengthConverter() {
double meters, feet;
cout << "Write the meter value: ";
cin >> meters;
feet = meters * 3.28084; // 1 meter = 3.28 feet
cout << "feet conversion: " << feet << " ft" << endl;
}
Then, I declared a main function. I used condition, loop, and control statements to convert as required among the three conversions.
Here, 1 is money conversion, 2 is temperature conversion, 3 is measurement conversion, and 4 will end the program. A switch statement is used to complete this task. The result is shown through Cout according to the condition.
int main() {
int choice;
do {
cout << "\nConverter Menu \n";
cout << "1. Currency conversion (money to USD)\n";
cout << "2. Temparature conversion (Celsius to fahrenheit)\n";
cout << "3. Length conversion (Meter to feet)\n";
cout << "4. Program End\n";
cout << "Your Choice: ";
cin >> choice;
switch (choice) {
case 1:
currencyConverter();
break;
case 2:
temperatureConverter();
break;
case 3:
lengthConverter();
break;
case 4:
cout << "Clossing the program!\n";
break;
default:
cout << "Incorrect input\n";
}
} while (choice != 4);
return 0;
}
I made the above work piece by piece in program form. I output the entire program through the online compiler and am very happy with the output.
Then I write the whole program in online compiler and get the output. I type 1 from the converter menu. Then I input 500 bdt. Then convert to usd and get 3.84 USD.
Then I enter 2 from the converter menu. Then type 500 Celsius as input. As output I get 932F. I have given the screen shot by blocking the red color in the picture.
Then I type 3 from the main menu. Then enter 500 meters to convert the measurement. Then I get 1640.42 feet as output. Below I have given screenshot with red color block.
SL No. | My Invited Steemit Friends |
---|---|
1 | @dove11 |
2 | @lirvic |
3 | @rmm31 |
This is my Twitter share link :
https://twitter.com/mahadih83660186/status/1892959712314110045?t=AQtJYnGS4gR0PYuWRsr97w&s=19