Skip to content

Commit

Permalink
C++ օրինակներ
Browse files Browse the repository at this point in the history
  • Loading branch information
armenbadal committed Nov 9, 2021
1 parent 45e628d commit 94c2389
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 0 deletions.
13 changes: 13 additions & 0 deletions code/multipleof3.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <iostream>

int main()
{
std::cout << "Ներմուծեք որևէ ամբողջ թիվ. ";
int number = 0;
std::cin >> number;

if( number % 3 == 0 )
std::cout << number << "-ը երեքի պատիկ է" << std::endl;

return 0;
}
15 changes: 15 additions & 0 deletions code/oddeven.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <iostream>

int main()
{
std::cout << "Ներմուծեք որևէ ամբողջ թիվ. ";
int number = 0;
std::cin >> number;

if( (number & 0x01) == 0x01 )
std::cout << number << "-ը կենտ է։" << std::endl;
else
std::cout << number << "-ը զույգ է։" << std::endl;

return 0;
}
31 changes: 31 additions & 0 deletions code/planets.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <array>
#include <iostream>
#include <string>

int main()
{
using namespace std;

const array<string, 8> planets{
"Փայլածու", // Մերկուրի
"Արուսյակ", // Վեներա
"Երկիր",
"Հրատ", // Մարս
"Լուսնթագ", // Յուպիտեր
"Երեւակ", // Սատուրն
"Ուրան",
"Նեպտուն"
};

cout << "Ներմուծեք մոլորակի համարը. ";
int index = 0;
cin >> index;

if( index >= 1 && index <= 8 )
cout << index << " համարով մոլորակը "
<< planets[index-1] << "ն է" << endl;
else
cout << index << " համարով մոլորակ չկա։" << endl;

return 0;
}
30 changes: 30 additions & 0 deletions code/planets2.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <iostream>
#include <string>
#include <vector>

int main()
{
using namespace std;

vector<string> planets;
planets.push_back("Փայլածու"); // Մերկուրի
planets.push_back("Արուսյակ"); // Վեներա
planets.push_back("Երկիր");
planets.push_back("Հրատ"); // Մարս
planets.push_back("Լուսնթագ"); // Յուպիտեր
planets.push_back("Երեւակ"); // Սատուրն
planets.push_back("Ուրան");
planets.push_back("Նեպտուն");

cout << "Ներմուծեք մոլորակի համարը. ";
int index = 0;
cin >> index;

if( index >= 1 && index <= 8 )
cout << index << " համարով մոլորակը "
<< planets[index-1] << "ն է" << endl;
else
cout << index << " համարով մոլորակ չկա։" << endl;

return 0;
}
17 changes: 17 additions & 0 deletions code/signof.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <iostream>

int main()
{
std::cout << "Ներմուծեք որևէ ամբողջ թիվ. ";
int number = 0;
std::cin >> number;

if( number > 0 )
std::cout << number << "-ը դրական է։" << std::endl;
else if( number < 0 )
std::cout << number << "-ը բացասական է։" << std::endl;
else
std::cout << "ներմուծված թիվը զրո է։" << std::endl;

return 0;
}
34 changes: 34 additions & 0 deletions code/sphere.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <iostream>
#include <numbers>

int main()
{
using namespace std;

cout << "Գնդի տրամագիծը (սմ). ";
double diameter = 0.0;
cin >> diameter;

cout << "Գնդի պատի հաստությունը (սմ). ";
double thickness = 0.0;
cin >> thickness;

const auto radius = diameter / 2;
const auto inner_radius = radius - thickness;

//const double PI = 3.1415;
using std::numbers::pi;

const auto inner_volume = (4 * pi * inner_radius * inner_radius * inner_radius) / 3;
cout << "Գնդի խոռոչի ծավալը (սմ³). " << inner_volume << endl;

const auto surface_area = 4 * pi * radius * radius;
cout << "Գնդի արտաքին մակերեսը (սմ²). " << surface_area << endl;

const double steel_density = 7.8; // g/sm³
const auto outer_volume = (4 * pi * radius * radius * radius) / 3;
const auto weight = steel_density * (outer_volume - inner_volume);
cout << "Գնդի զանգվածը (գ). " << weight << endl;

return 0;
}

0 comments on commit 94c2389

Please sign in to comment.