diff --git a/.gitignore b/.gitignore index 620d3dc..1188fd3 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,25 @@ *.lai *.la *.a + +# Compiled Executables +*.exe +*.out + +# Archives +*.7z +*.zip + +# MSVC Generated Files +*.idb +*.ilk +*.log +*.obj +*.pdb +*.sdf +*.sln +*.suo +*.tlog +*.filters +*.vcxproj +*.lastbuildstate \ No newline at end of file diff --git a/austinov.02.setting_out_to_cpp/01_address.cpp b/austinov.02.setting_out_to_cpp/01_address.cpp new file mode 100644 index 0000000..059674d --- /dev/null +++ b/austinov.02.setting_out_to_cpp/01_address.cpp @@ -0,0 +1,11 @@ +// nameaddr.cpp displays the name and address of it's author + +#include + +int main() +{ + using namespace std; + cout << "Artem Ustinov" << endl; + cout << "artem@ustinov.org.ua" << endl; + return 0; +} diff --git a/austinov.02.setting_out_to_cpp/02_distance.cpp b/austinov.02.setting_out_to_cpp/02_distance.cpp new file mode 100644 index 0000000..e3ab0fa --- /dev/null +++ b/austinov.02.setting_out_to_cpp/02_distance.cpp @@ -0,0 +1,14 @@ +// fl2yd.cpp asks the length in furlong and converts to yards + +#include + +int main(void) +{ + int l; + l = 0; + std::cout << "Please specify length in furlolgs: "; + std::cin >> l; + std::cout << "The converted length is "; + std::cout << l * 220 << " yards" << std::endl; + return 0; +} diff --git a/austinov.02.setting_out_to_cpp/03_mices.cpp b/austinov.02.setting_out_to_cpp/03_mices.cpp new file mode 100644 index 0000000..98ae58d --- /dev/null +++ b/austinov.02.setting_out_to_cpp/03_mices.cpp @@ -0,0 +1,22 @@ +// fourlines.cpp produces four lines using three functions + +#include + +void first(void) +{ + std::cout << "Three blind mice" << std::endl; +} + +void second(void) +{ + std::cout << "See how they run" << std::endl; +} + +int main(void) +{ + first(); + first(); + second(); + second(); + return 0; +} diff --git a/austinov.02.setting_out_to_cpp/04_months.cpp b/austinov.02.setting_out_to_cpp/04_months.cpp new file mode 100644 index 0000000..c22c64a --- /dev/null +++ b/austinov.02.setting_out_to_cpp/04_months.cpp @@ -0,0 +1,13 @@ +// age2mnth.cpp asks you the age and then shows it in months + +#include + +int main(void) +{ + int age; + age = 0; + std::cout << "Please enter your age: "; + std::cin >> age; + std::cout << "Your age in month is " << age * 12 << std::endl; + return 0; +} diff --git a/austinov.02.setting_out_to_cpp/05_degrees.cpp b/austinov.02.setting_out_to_cpp/05_degrees.cpp new file mode 100644 index 0000000..4988fdc --- /dev/null +++ b/austinov.02.setting_out_to_cpp/05_degrees.cpp @@ -0,0 +1,21 @@ +// cd2fd.cpp asks you the celsium degrees and converts to farenheit + +#include + +int c2f(float c) +{ + return 1.8 * c + 32.0; +} + +int main(void) +{ + float c; + std::cout << "Please enter a Celsius value: "; + std::cin >> c; + std::cout << c << " degrees Celsius is " << c2f(c); + std::cout << " degrees Farenheit." << std::endl; + std::cout << "For reference,here is the formula for making the "; + std::cout << "conversion:\nFahrenheit = "; + std::cout << "1.8 × degrees Celsius + 32.0" << std::endl; + return 0; +} diff --git a/austinov.02.setting_out_to_cpp/06_lightyrs.cpp b/austinov.02.setting_out_to_cpp/06_lightyrs.cpp new file mode 100644 index 0000000..e9a0e84 --- /dev/null +++ b/austinov.02.setting_out_to_cpp/06_lightyrs.cpp @@ -0,0 +1,18 @@ +// fl2yd.cpp asks the length in furlong and converts to yards + +#include + +int ly2au(float d) +{ + return 63240 * d; +} + +int main(void) +{ + float d; + std::cout << "Enter the number in light years: "; + std::cin >> d; + std::cout << d << " light years = " << ly2au(d); + std::cout << " astronomical units." << std::endl; + return 0; +} diff --git a/austinov.02.setting_out_to_cpp/07_time.cpp b/austinov.02.setting_out_to_cpp/07_time.cpp new file mode 100644 index 0000000..0f77d03 --- /dev/null +++ b/austinov.02.setting_out_to_cpp/07_time.cpp @@ -0,0 +1,19 @@ +// hour:min.cpp displays the entered hour and minute in HH:MM format + +#include + +void pretty_print(int hh, int mm) +{ + std::cout << "Time: " << hh << ":" << mm << std::endl; +} + +int main(void) +{ + int hh, mm; + std::cout << "Enter the number of hours: "; + std::cin >> hh; + std::cout << "Enter the number of minutes: "; + std::cin >> mm; + pretty_print(hh, mm); + return 0; +} diff --git a/austinov.03.dealing_with_data/01_bmi.cpp b/austinov.03.dealing_with_data/01_bmi.cpp new file mode 100644 index 0000000..a152d80 --- /dev/null +++ b/austinov.03.dealing_with_data/01_bmi.cpp @@ -0,0 +1,34 @@ +// bmi.cpp makes different conversions and calculates the BMI + +#include + +int main() +{ + int h_ft = 0; + int h_in = 0; + int w_lbs = 0; + + std::cout << "This program wants to calculate your BMI" << std::endl; + std::cout << "Please enter your height in feet and inches..."; + std::cout << std::endl << "Enter feet: "; + std::cin >> h_ft; + std::cout << "And inches: "; + std::cin >> h_in; + std::cout << "Please also enter your weight in pounds: "; + std::cin >> w_lbs; + + // getting total height in inches + h_in += h_ft / 12; + + // defining the multipliers for Height and Weight + const float H_Mult = 0.0254; + const float W_Mult = 2.2; + + // converting to meters and kilograms accordingly + float h_m = H_Mult * h_in; + float w_kg = W_Mult * w_lbs; + + std::cout << "The BMI is " << w_kg / (h_m * h_m) << std::endl; + + return 0; +} diff --git a/austinov.03.dealing_with_data/02_degrees.cpp b/austinov.03.dealing_with_data/02_degrees.cpp new file mode 100644 index 0000000..89425dd --- /dev/null +++ b/austinov.03.dealing_with_data/02_degrees.cpp @@ -0,0 +1,34 @@ +// degrees.cpp converts D-M-S of ARC into decimal Degrees + +#include + +int main() +{ + int i_d, i_m, i_s = 0; + + std::cout << "I will convert your coordinate into degrees" << std::endl; + std::cout << "Please enter it in degrees, minutes and seconds..."; + std::cout << std::endl << "Enter degrees: "; + std::cin >> i_d; + std::cout << "and minutes: "; + std::cin >> i_m; + std::cout << "and seconds: "; + std::cin >> i_s; + + // defining the multipliers + const int S_IN_M = 60; + const int S_IN_D = 3600; + + // the result should be floating point + double d_res; + + std::cout << i_d << " degrees, "; + std::cout << i_m << " minutes, "; + std::cout << i_s << " seconds = "; + + std::cout.precision(7); // setting the precision for result + std::cout << (i_d + static_cast(i_m * S_IN_M + i_s) / S_IN_D); + std::cout << " decimal degrees." << std::endl; + + return 0; +} diff --git a/austinov.03.dealing_with_data/03_secs.cpp b/austinov.03.dealing_with_data/03_secs.cpp new file mode 100644 index 0000000..c9677e9 --- /dev/null +++ b/austinov.03.dealing_with_data/03_secs.cpp @@ -0,0 +1,28 @@ +// secs.cpp converts seconds into days, hours, minutes and seconds + +#include + +int main() +{ + int i_s = 0; + + std::cout << "I'll show you seconds in days, hrs, min, sec..."; + std::cout << std::endl << "Enter seconds: "; + std::cin >> i_s; + + // defining the multipliers + const int S_IN_M = 60; + const int S_IN_H = S_IN_M * 60; + const int S_IN_D = S_IN_H * 24; + + std::cout << i_s << " seconds equals to "; + std::cout << i_s / S_IN_D << " days, "; + i_s = i_s % S_IN_D; + std::cout << i_s / S_IN_H << " hours, "; + i_s = i_s % S_IN_H; + std::cout << i_s / S_IN_M << " minutes and "; + i_s = i_s % S_IN_M; + std::cout << i_s << " seconds." << std::endl; + + return 0; +} diff --git a/austinov.03.dealing_with_data/04_pops.cpp b/austinov.03.dealing_with_data/04_pops.cpp new file mode 100644 index 0000000..af4bc0c --- /dev/null +++ b/austinov.03.dealing_with_data/04_pops.cpp @@ -0,0 +1,22 @@ +// pops.cpp shows you the percentage of the second number in first + +#include + +int main() +{ + unsigned long long ull_world = 0; + unsigned long ul_ukraine = 0; + + std::cout << "I'll show you the percentage..." << std::endl;; + std::cout << "Specify the world population (is around 7B): "; + std::cin >> ull_world; + std::cout << "And the population of Ukraine (around 45M): "; + std::cin >> ul_ukraine; + + std::cout << "The population of Ukraine is "; + std::cout.precision(4); + std::cout << static_cast(ul_ukraine) / (ull_world / 100); + std::cout << "\% of World's population." << std::endl; + + return 0; +} diff --git a/austinov.03.dealing_with_data/05_mpg.cpp b/austinov.03.dealing_with_data/05_mpg.cpp new file mode 100644 index 0000000..03477da --- /dev/null +++ b/austinov.03.dealing_with_data/05_mpg.cpp @@ -0,0 +1,23 @@ +// mpg.cpp counts the fuel consumption in mpg or lp100km + +#include + +int main() +{ + unsigned int ui_dist = 0; + unsigned int ui_fuel = 0; + + std::cout << "I can count the Fuel Consumption." << std::endl;; + std::cout << "Enter the mileage (in miles or km): "; + std::cin >> ui_dist; + std::cout << "And specify the fuel amount (in gal or liter): "; + std::cin >> ui_fuel; + + std::cout << "The average consumption is around "; + std::cout.precision(3); + std::cout << ui_dist / ui_fuel << " mpg," << std::endl;; + std::cout << "or " << 100 * ui_fuel / static_cast(ui_dist); + std::cout << " liters per 100 km accordingly." << std::endl; + + return 0; +} diff --git a/austinov.03.dealing_with_data/06_lkm2mpg.cpp b/austinov.03.dealing_with_data/06_lkm2mpg.cpp new file mode 100644 index 0000000..d6b0a1b --- /dev/null +++ b/austinov.03.dealing_with_data/06_lkm2mpg.cpp @@ -0,0 +1,21 @@ +// lkm2mpg.cpp converts mpg to lp100km + +#include + +int main() +{ + unsigned int ui_lkm = 0; + + std::cout << "I can convert liters per 100 km into mpg." << std::endl; + std::cout << "Enter the consumption value to convert: "; + std::cin >> ui_lkm; + + const double MI_IN_100KM = 62.1371; + const double L_IN_GAL = 3.78541; + const double RATIO = MI_IN_100KM * L_IN_GAL; + + std::cout << ui_lkm << " liters per 100 km is around "; + std::cout << RATIO / ui_lkm << " mpg." << std::endl; + + return 0; +} diff --git a/austinov.04.compound_types/01_namesages.cpp b/austinov.04.compound_types/01_namesages.cpp new file mode 100644 index 0000000..123eccf --- /dev/null +++ b/austinov.04.compound_types/01_namesages.cpp @@ -0,0 +1,31 @@ +// it asks for a name few times and stores that into array + +#include +#include + +int main() +{ + struct person + { + std::string fname; + std::string lname; + char grade; + short age; + }; + + person p0; + std::cout << "What is your first name? "; + getline(std::cin, p0.fname); + std::cout << "What is your last name? "; + getline(std::cin, p0.lname); + std::cout << "What letter grade do you deserve? "; + std::cin >> p0.grade; + std::cout << "What is your age? "; + std::cin >> p0.age; + + std::cout << "Name: " << p0.lname << ", " << p0.fname << std::endl; + std::cout << "Grade: " << static_cast(p0.grade + 1) << std::endl; + std::cout << "Age: " << p0.age << std::endl; + + return 0; +}; diff --git a/austinov.04.compound_types/02_namesages.cpp b/austinov.04.compound_types/02_namesages.cpp new file mode 100644 index 0000000..123eccf --- /dev/null +++ b/austinov.04.compound_types/02_namesages.cpp @@ -0,0 +1,31 @@ +// it asks for a name few times and stores that into array + +#include +#include + +int main() +{ + struct person + { + std::string fname; + std::string lname; + char grade; + short age; + }; + + person p0; + std::cout << "What is your first name? "; + getline(std::cin, p0.fname); + std::cout << "What is your last name? "; + getline(std::cin, p0.lname); + std::cout << "What letter grade do you deserve? "; + std::cin >> p0.grade; + std::cout << "What is your age? "; + std::cin >> p0.age; + + std::cout << "Name: " << p0.lname << ", " << p0.fname << std::endl; + std::cout << "Grade: " << static_cast(p0.grade + 1) << std::endl; + std::cout << "Age: " << p0.age << std::endl; + + return 0; +}; diff --git a/austinov.04.compound_types/03_lastfirst.cpp b/austinov.04.compound_types/03_lastfirst.cpp new file mode 100644 index 0000000..5ad2e01 --- /dev/null +++ b/austinov.04.compound_types/03_lastfirst.cpp @@ -0,0 +1,24 @@ +// it asks for a first and last name and then shows it comma separated + +#include +#include + +int main() +{ + char first [10] = {}; + char last [13] = {}; + + std::cout << "What is your first name? "; + std::cin.getline(first, 10); + std::cout << "What is your last name? "; + std::cin.getline(last, 13); + + char output [25] = {}; + strcat(output, last); + strcat(output, ", "); + strcat(output, first); + std::cout << "Here's the information in a single string: "; + std::cout << output << std::endl; + + return 0; +}; diff --git a/austinov.04.compound_types/04_strlastfirst.cpp b/austinov.04.compound_types/04_strlastfirst.cpp new file mode 100644 index 0000000..3f95d75 --- /dev/null +++ b/austinov.04.compound_types/04_strlastfirst.cpp @@ -0,0 +1,20 @@ +// it asks for a first and last name and then shows it comma separated + +#include +#include + +int main() +{ + std::string first, last, output; + + std::cout << "What is your first name? "; + getline(std::cin, first); + std::cout << "What is your last name? "; + getline(std::cin, last); + + output = last + ", " + first; + std::cout << "Here's the information in a single string: "; + std::cout << output << std::endl; + + return 0; +}; diff --git a/austinov.04.compound_types/05_candybar.cpp b/austinov.04.compound_types/05_candybar.cpp new file mode 100644 index 0000000..850c1a0 --- /dev/null +++ b/austinov.04.compound_types/05_candybar.cpp @@ -0,0 +1,13 @@ +// candybar.cpp declares the structure and populates an instance + +#include +#include + +int main() +{ + struct candybar {std::string n; float w; int c;}; + candybar snack = {"Mocha Munch", 2.3, 350}; + std::cout << snack.n << ", " << snack.w << ", " << snack.c << std::endl; + + return 0; +}; diff --git a/austinov.04.compound_types/06_candybarr.cpp b/austinov.04.compound_types/06_candybarr.cpp new file mode 100644 index 0000000..dd35274 --- /dev/null +++ b/austinov.04.compound_types/06_candybarr.cpp @@ -0,0 +1,24 @@ +// candybar.cpp declares the structure and populates an instance + +#include +#include + +int main() +{ + struct candybar {std::string n; float w; int c;}; + candybar cba [3]; + cba[0].n = "Candy Bar 0"; + cba[0].w = 0.9; + cba[0].c = 210; + std::cout << cba[0].n << ", " << cba[0].w << ", " << cba[0].c << std::endl; + cba[1].n = "Candy Bar 1"; + cba[1].w = 1.9; + cba[1].c = 321; + std::cout << cba[1].n << ", " << cba[1].w << ", " << cba[1].c << std::endl; + cba[2].n = "Candy Bar 2"; + cba[2].w = 2.9; + cba[2].c = 432; + std::cout << cba[2].n << ", " << cba[2].w << ", " << cba[2].c << std::endl; + + return 0; +}; diff --git a/austinov.04.compound_types/07_pizza.cpp b/austinov.04.compound_types/07_pizza.cpp new file mode 100644 index 0000000..3085686 --- /dev/null +++ b/austinov.04.compound_types/07_pizza.cpp @@ -0,0 +1,19 @@ +// pizza.cpp introduces a pizzacompany structure and populates one instance + +# include +# include + +int main() +{ + struct pizza_company {std::string name; int d; float w;} pizza; + std::cout << "Please specify a company: "; + getline(std::cin, pizza.name); + std::cout << "Please enter the diameter in mm: "; + std::cin >> pizza.d; + std::cout << "Please specify weight in kg: "; + std::cin >> pizza.w; + std::cout << std::endl << "You have entered: "; + std::cout << pizza.name << ", " << pizza.d << ", " << pizza.w << std::endl; + + return 0; +} diff --git a/austinov.04.compound_types/08_newpizza.cpp b/austinov.04.compound_types/08_newpizza.cpp new file mode 100644 index 0000000..2457006 --- /dev/null +++ b/austinov.04.compound_types/08_newpizza.cpp @@ -0,0 +1,21 @@ +// pizza.cpp uses new to allocate the structure + +# include +# include + +int main() +{ + struct pizza_company {std::string name; int d; float w;}; + pizza_company* p_pizza = new pizza_company; + std::cout << "Please specify a company: "; + getline(std::cin, p_pizza->name); + std::cout << "Please enter the diameter in mm: "; + std::cin >> p_pizza->d; + std::cout << "Please specify weight in kg: "; + std::cin >> p_pizza->w; + std::cout << std::endl << "You have entered: "; + std::cout << p_pizza->name << ", " << p_pizza->d << ", " << p_pizza->w; + std::cout << std::endl; + + return 0; +} diff --git a/austinov.04.compound_types/09_newcandybarr.cpp b/austinov.04.compound_types/09_newcandybarr.cpp new file mode 100644 index 0000000..0484ad8 --- /dev/null +++ b/austinov.04.compound_types/09_newcandybarr.cpp @@ -0,0 +1,27 @@ +// candybar.cpp declares the structure and populates an instance + +# include +# include + +int main() +{ + struct candybar {std::string n; float w; int c;}; + candybar * p_cba = new candybar[3]; + p_cba[0].n = "Candy Bar 0"; + p_cba[0].w = 0.9; + p_cba[0].c = 210; + std::cout << p_cba[0].n << ", " << p_cba[0].w << ", " << p_cba[0].c ; + std::cout << std::endl; + p_cba[1].n = "Candy Bar 1"; + p_cba[1].w = 1.9; + p_cba[1].c = 321; + std::cout << p_cba[1].n << ", " << p_cba[1].w << ", " << p_cba[1].c ; + std::cout << std::endl; + p_cba[2].n = "Candy Bar 2"; + p_cba[2].w = 2.9; + p_cba[2].c = 432; + std::cout << p_cba[2].n << ", " << p_cba[2].w << ", " << p_cba[2].c ; + std::cout << std::endl; + + return 0; +}; diff --git a/austinov.04.compound_types/10_40yddash.cpp b/austinov.04.compound_types/10_40yddash.cpp new file mode 100644 index 0000000..7def011 --- /dev/null +++ b/austinov.04.compound_types/10_40yddash.cpp @@ -0,0 +1,20 @@ +// 40yddash.cpp asks for the sprint times and shows the average + +# include +# include + +int main() +{ + std::array lap_times; + float time_sum = 0.0; + for (int i = 0; (i < lap_times.max_size()); i++) + { + std::cout << "Please enter the result in seconds: "; + std::cin >> lap_times[i]; + time_sum += lap_times[i]; + }; + std::cout << "The average time is: " << time_sum / lap_times.size(); + std::cout << std::endl; + + return 0; +};