Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,26 @@
*.lai
*.la
*.a

# Compiled Executables
*.exe
*.out

# Archives
*.7z
*.zip

# MSVC Generated Files
*.idb
*.ilk
*.log
*.obj
*.pdb
*.sdf
*.sln
*.suo
*.tlog
*.filters
*.opensdf
*.vcxproj
*.lastbuildstate
11 changes: 11 additions & 0 deletions austinov.02.setting_out_to_cpp/01_address.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// nameaddr.cpp displays the name and address of it's author

#include <iostream>

int main()
{
using namespace std;
cout << "Artem Ustinov" << endl;
cout << "artem@ustinov.org.ua" << endl;
return 0;
}
14 changes: 14 additions & 0 deletions austinov.02.setting_out_to_cpp/02_distance.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// fl2yd.cpp asks the length in furlong and converts to yards

#include <iostream>

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;
}
22 changes: 22 additions & 0 deletions austinov.02.setting_out_to_cpp/03_mices.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// fourlines.cpp produces four lines using three functions

#include <iostream>

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;
}
13 changes: 13 additions & 0 deletions austinov.02.setting_out_to_cpp/04_months.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// age2mnth.cpp asks you the age and then shows it in months

#include <iostream>

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;
}
21 changes: 21 additions & 0 deletions austinov.02.setting_out_to_cpp/05_degrees.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// cd2fd.cpp asks you the celsium degrees and converts to farenheit

#include <iostream>

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;
}
18 changes: 18 additions & 0 deletions austinov.02.setting_out_to_cpp/06_lightyrs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// fl2yd.cpp asks the length in furlong and converts to yards

#include <iostream>

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;
}
19 changes: 19 additions & 0 deletions austinov.02.setting_out_to_cpp/07_time.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// hour:min.cpp displays the entered hour and minute in HH:MM format

#include <iostream>

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;
}
34 changes: 34 additions & 0 deletions austinov.03.dealing_with_data/01_bmi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// bmi.cpp makes different conversions and calculates the BMI

#include <iostream>

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;
}
34 changes: 34 additions & 0 deletions austinov.03.dealing_with_data/02_degrees.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// degrees.cpp converts D-M-S of ARC into decimal Degrees

#include <iostream>

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<double>(i_m * S_IN_M + i_s) / S_IN_D);
std::cout << " decimal degrees." << std::endl;

return 0;
}
28 changes: 28 additions & 0 deletions austinov.03.dealing_with_data/03_secs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// secs.cpp converts seconds into days, hours, minutes and seconds

#include <iostream>

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;
}
22 changes: 22 additions & 0 deletions austinov.03.dealing_with_data/04_pops.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// pops.cpp shows you the percentage of the second number in first

#include <iostream>

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<long double>(ul_ukraine) / (ull_world / 100);
std::cout << "\% of World's population." << std::endl;

return 0;
}
23 changes: 23 additions & 0 deletions austinov.03.dealing_with_data/05_mpg.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// mpg.cpp counts the fuel consumption in mpg or lp100km

#include <iostream>

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<double>(ui_dist);
std::cout << " liters per 100 km accordingly." << std::endl;

return 0;
}
21 changes: 21 additions & 0 deletions austinov.03.dealing_with_data/06_lkm2mpg.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// lkm2mpg.cpp converts mpg to lp100km

#include <iostream>

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;
}
31 changes: 31 additions & 0 deletions austinov.04.compound_types/01_namesages.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// it asks for a name few times and stores that into array

#include <iostream>
#include <string>

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<char>(p0.grade + 1) << std::endl;
std::cout << "Age: " << p0.age << std::endl;

return 0;
};
31 changes: 31 additions & 0 deletions austinov.04.compound_types/02_namesages.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// it asks for a name few times and stores that into array

#include <iostream>
#include <string>

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<char>(p0.grade + 1) << std::endl;
std::cout << "Age: " << p0.age << std::endl;

return 0;
};
Loading