Skip to content

Instantly share code, notes, and snippets.

@Darklega228
Created September 22, 2024 14:01
Show Gist options
  • Save Darklega228/28b236d07857d77d7afc2a99cd7e8b7f to your computer and use it in GitHub Desktop.
Save Darklega228/28b236d07857d77d7afc2a99cd7e8b7f to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
// Задание 1
/*int main()
{
setlocale(0, "");
int a = 10;
double b = 20.0;
string c = "30";
char d = 'x';
int* pa = &a;
double* pb = &b;
string* pc = &c;
char* pd = &d;
cout << "Размер указателя на int: " << sizeof(pa) << " байт\n";
cout << "Размер указателя на double: " << sizeof(pb) << " байт\n";
cout << "Размер указателя на string: " << sizeof(pc) << " байт\n";
cout << "Размер указателя на char: " << sizeof(pd) << " байт\n";
ptrdiff_t distanceABinInts = reinterpret_cast<char*>(pb) - reinterpret_cast<char*>(pa);
ptrdiff_t distanceBCinChars = reinterpret_cast<char*>(pc) - reinterpret_cast<char*>(pb);
ptrdiff_t distanceCDinChars = reinterpret_cast<char*>(pd) - reinterpret_cast<char*>(pc);
cout << "\nРасстояние между int и double в байтах: " << distanceABinInts << "\n";
cout << "Расстояние между double и string в байтах: " << distanceBCinChars << "\n";
cout << "Расстояние между string и char в байтах: " << distanceCDinChars << "\n";
}*/
//Задание 2
/*int main()
{
setlocale(0, "");
int number;
cout << "Введите число: ";
cin >> number;
int* ptr = &number;
int square = (*ptr) * (*ptr);
int cube = (*ptr) * (*ptr) * (*ptr);
int fourthStepen = (*ptr) * (*ptr) * (*ptr) * (*ptr);
cout << *ptr << "^2 = " << square << "\n";
cout << *ptr << "^3 = " << cube << "\n";
cout << *ptr << "^4 = " << fourthStepen << "\n";
}*/
//Задание 3
/*int main()
{
setlocale(0, "");
int num1 = 5, num2 = 10, result = 0;
int* ptr1 = &num1;
int* ptr2 = &num2;
int* ptrResult = &result;
int** ptrPtr1 = &ptr1;
int** ptrPtr2 = &ptr2;
int** ptrPtrResult = &ptrResult;
**ptrPtrResult = **ptrPtr1 + **ptrPtr2;
cout << "Сумма " << **ptrPtr1 << " и " << **ptrPtr2 << " = " << **ptrPtrResult << "\n";
}*/
// Задание 4
int main()
{
setlocale(0, "");
double height, weight;
cout << "Введите ваш рост (в см): ";
cin >> height;
cout << "Введите ваш реальный вес (в кг): ";
cin >> weight;
double idealWeight = height - 110;
double* pWeight = &weight;
double* pIdealWeight = &idealWeight;
double** ppWeight = &pWeight;
double** ppIdealWeight = &pIdealWeight;
double*** pppWeight = &ppWeight;
double*** pppIdealWeight = &ppIdealWeight;
double difference = ***pppWeight - ***pppIdealWeight;
if (difference > 0)
{
cout << "Вам нужно сбросить " << difference << " кг.\n";
}
else if (difference < 0)
{
cout << "Вам нужно набрать " << -difference << " кг.\n";
}
else
{
cout << "Ваш вес уже идеален!\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment