Код: Выделить всё
//---------------------------------------------------------------------------
#include <vcl>
#include <iostream>
#include <conio>
#include <fstream>
//#include <random>
#include <ctime>
#include <iomanip>
#include <clocale>
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma argsused
using namespace std;
int a=10,b=30,x=0,a1=1,b1=0,number,n1,n2,n3,mx,Counter=0,pn=1;
float ARFM,klv,Sum;
wstring name;
ofstream file2;
ifstream file1;
int N;
bool First = true, EstChetnie = false;
void Zadanie1(void)
{
cout << "\nZadanie 1:";
cout << "\nNajmite 1 dlya vvoda s pomoshiyu randoma ili 2 dlya samostoyatelnogo vvoda";
while(x > 2 || x < 1)
{
cout << "\t\nKak vi budete vvodit?";
cin >> x;
}
file2.open("input.txt");
switch(x)
{
case 1:
while(a1 >= b1)
{
cout << "\t\nVvedite nachalo dlya randoma: ";
cin >> a1;
cout << "\t\nVvedite konec dlya randoma: ";
cin >> b1;
}
for(int i = 0; i < N; i++)
{
file2 << rand()%(b1-a1) + a1;
if(i != (N-1))
file2 << "\n";
}
break;
case 2:
for(int i = 0, e; i < N; i++)
{
cout << "\nVvedite chislo: ";
cin >> e;
file2 << e;
if(i != (N-1))
file2 << "\n";
}
break;
}
file2.close(); //output file
file1.open("input.txt"); //input file
cout << "\nVasha posledovatelnost:" << endl;
while(!file1.eof())
{
file1 >> number;
cout << number << " ";
}
file1.close();
file1.clear();
}
void Zadanie2(void)
{
cout << "\n\nZadanie 2:" << endl;
file1.open("input.txt");
/*
int pos = file1.tellg();
file1.seekg(0);
pos = file1.tellg();
*/
Sum = 0;
klv = 0;
for(int i = 1; i <= N; i++)
{
file1 >> n1;
if(n1 > 0)
{
Sum += n1;
klv++;
}
}
file1.close();
file1.clear();
ARFM = Sum/klv;
cout << "\nSumma = " << Sum << endl;
cout << "\nKolichestvo = " << klv << endl;
cout << "\nSrednee Arifmeticheskoe = "/*<<setprecision(2)*/<< ARFM << endl;
}
void Zadanie3(void)
{
cout << "\nZadanie 3:" << endl
file1.open("input.txt");
file2.open("output.txt");
n1=n2=n3=NULL;
file1 >> n3;
for(int i=0; i<N; i++)
{
n1=n2;
n2=n3;
if(i == (N-1))
n3=NULL;
else
file1 >> n3;
if((n1+n3) > n2)
{
if(!First)
file2 << "\n";
file2 << n2;
First = false;
}
/*
n1=n2;
n2=n3;
if(file1 >> n4)
n3=n4;
else
n3=0;
if((n1+n3) > n2)
{
file2 << n2 << endl;
}
*/
}
file1.close();
file1.clear();
file2.close();
file1.open("output.txt");
cout << "\n\nOutput.txt:\n";
while(!file1.eof())
{
file1 >> number;
cout << number << " ";
}
file1.close();
file1.clear();
}
void Zadanie4(void)
{
cout << "\n\nZadanie 4:" << endl;
file1.open("output.txt");
while(!file1.eof())
{
file1 >> number;
Counter++;
if(number%2==0)
{
if(!EstChetnie)
{
mx = number;
pn = Counter;
EstChetnie = true;
}
if(number > mx)
{
mx = number;
pn = Counter;
}
}
}
file1.close();
if(!EstChetnie)
cout << "\nNet chetnih elementov.";
else
{
cout << "\nmx element=" << mx;
cout << "\nnomer=" << pn; //Pascal-style
}
}
int main(int argc, char* argv[])
{
srand(time(NULL));
setlocale(LC_ALL, "Rus");
cout << "Independent work on C++.\nVariant 3.";
N = rand()%(b-a) + a;
cout << "\nVasha posledovatelnost iz " << N << " chisel";
Zadanie1();
Zadanie2();
Zadanie3();
Zadanie4();
getch();
return 0;
}
//---------------------------------------------------------------------------
