Skip to content

Instantly share code, notes, and snippets.

@ernado
Created February 15, 2013 15:05
Show Gist options
  • Save ernado/4960898 to your computer and use it in GitHub Desktop.
Save ernado/4960898 to your computer and use it in GitHub Desktop.
#include "stdafx.h"
#include "lab1_216.h"
#include <iostream>
#include <fstream>
#include <string>
#define max(a,b,c) ((a > b) ? ((a > c)? a : c) : (b > c) ? b : c)
using namespace std;
const int VAR = 16;
const string FNAME = "Разумов.txt";
typedef int* TintPointer;
typedef int& TintReference;
struct Kaf
{
string title, zav, website;
int students;
};
void main(void)
{
system("chcp 1251 > nul");
cout << "п.4.3. Описание переменных и массивов\n";
int iVar, iMas[20]; long lVar, lMas[20]; char cVar, cMas[20]; float fVar, fMas[20]; double dVar, dMas[20]; bool bVar, bMas[20];
iVar = 10; lVar = 103213; cVar = 'Z'; fVar = 0.156f; dVar = -15.3; bVar = true;
iMas[VAR] = -16; lMas[VAR] = 22213; cMas[VAR] = 'K'; fMas[VAR] = 23.2f; dMas[VAR] = 145.3; bMas[VAR] = false;
cout << "IVar = " << iVar << endl;
cout << "lVar = " << lVar << endl;
cout << "cVar = " << cVar << endl;
cout << "fVar = " << fVar << endl;
cout << "dVar = " << dVar << endl;
cout << "bVar = " << bVar << endl;
cout << "iMas[16] = " << iMas[VAR] << endl;
cout << "lMas[16] = " << lMas[VAR] << endl;
cout << "cMas[16] = " << cMas[VAR] << endl;
cout << "fMas[16] = " << fMas[VAR] << endl;
cout << "dMas[16] = " << dMas[VAR] << endl;
cout << "bMas[16] = " << bMas[VAR] << endl;
cout<<"\nп.4.4. Использование указателей и ссылок.\n";
TintReference rInt = iVar; TintPointer pInt = &iVar;
cout << "&iVar = " << &iVar << endl;
cout << "&rInt = " << &rInt << endl;
cout << "pInt = " << pInt << endl;
cout << "*pInt = " << *pInt << endl;
cout << "rInt = " << rInt << endl;
cout<<"\nп.4.5. Использование структур данных.\n";
Kaf k1 = {"Валеологии", "Смит Д.", "val.ggtu.gov", 278}, k2 = {"Темпорального управления", "Доктор К.", "policebox.com", 2};
Kaf kMas[20]; kMas[VAR] = k2;
cout << "k1 = " << endl;
cout << "Title: " << k1.title << ", zav: " << k1.zav << ", website: " << k1.website << ", students: " << k1.students << endl;
cout << "kMas[16] = " << endl;
cout << "Title: " << kMas[VAR].title << ", zav: " << kMas[VAR].zav << ", website: " << kMas[VAR].website << ", students: " << kMas[VAR].students << endl;
cout<<"\nп.4.6. Использование оператора ветвления (if) и составного оператора.\n";
cout << "Введите любое целое число: "; cin >> iVar;
if (iVar % 2) cout << "Число нечетное"; else cout << "Число четное"; cout << endl;
cout << "Введите число от одного до пяти: "; cin >> iVar;
cout << "Вы ввели цифру";
switch (iVar)
{
case 1: cout << " один"; break;
case 2: cout << " два"; break;
case 3: cout << " три"; break;
case 4: cout << " четыре"; break;
case 5: cout << " пять"; break;
default: cout << ", которая оказалась вне диапазона"; break;
}
cout << endl;
cout<<"\nп.4.7. Описание функции и вызов её из другого модуля.\n";
int iMast[5] = {1, 2, 3, 4, 5};
cout << "Произведение элементов массива: " << iMasMultiply(iMast, 5) << endl; //120
cout<<"\nп.4.8. Работа с текстовыми файлами с использованием потоков.\n";
fstream of(FNAME, ios::out); of << "Разумов Александр Андреевич, группа ИУ5-22, Вариант № 16\n"; of.close();
of.open(FNAME, ios::in); string buff; getline(of, buff); of.close();
cout << buff << endl;
cout<<"\nИспользование макроса:\n";
cout << "Максимальное число из (4,2,8): " << max(4, 2, 8) << endl; //8
system("PAUSE");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment