0% found this document useful (0 votes)
42 views4 pages

Finaluris Bileti 2 1

The document contains 4 code snippets that demonstrate various C++ programming concepts: 1) Functions for calculating values based on input and conditionals. 2) Reading data from a file into vectors and performing operations on the vector elements. 3) Defining a struct and overloading functions to return struct elements or pass by reference. 4) Defining a class with properties and methods, reading object data from a file, and comparing objects to find minimum, maximum values.

Uploaded by

nino gudadze
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views4 pages

Finaluris Bileti 2 1

The document contains 4 code snippets that demonstrate various C++ programming concepts: 1) Functions for calculating values based on input and conditionals. 2) Reading data from a file into vectors and performing operations on the vector elements. 3) Defining a struct and overloading functions to return struct elements or pass by reference. 4) Defining a class with properties and methods, reading object data from a file, and comparing objects to find minimum, maximum values.

Uploaded by

nino gudadze
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1)

#include <iostream>
#include <algorithm>
using namespace std;

double calculation(double x)
{
if (x < 7) return x * x * x - 100;
else if (x == 7) return 11 + 2 * x;
else return 4 * x - 7;
}

int main()
{
double arr[25];
double a;
for (size_t i = 0; i < 25; i++)
{
cin >> a;
arr[i] = calculation(a);
}
cout << "25is toli elementebis raodenobaa: " << count(begin(arr), end(arr), 25) << endl;
cout << count_if(begin(arr), end(arr), [](double k) {return k < -101 || k > 60; });

2)

#include <iostream>
#include <vector>
#include <fstream>
using namespace std;

void printVector(const vector<double>& a)


{
for (size_t i = 0; i < a.size(); i++)
{
cout << a[i] << '\t';
if ((i + 1) % 5 == 0) cout << endl;
}
}

int main()
{
vector<double> vec;
vector<double> vec2;
double k;
ifstream ifs("reals.txt");
while (ifs >> k) {
vec.push_back(k);
}
for (size_t i = 0; i < vec.size(); i++)
{
if (vec[i] > -15 && vec[i] < 72) vec2.push_back(vec[i]);
}
printVector(vec);
printVector(vec2);
int count{};
for (size_t i = 0; i < vec.size(); i++)
{
if (vec[i] >= 72 && vec[i] <= 15) count++;
}
cout << count << endl;
for (size_t i = 0; i < vec2.size(); i++)
{
if (i % 2 != 0) vec[i] = pow(vec[i], 10);
}
printVector(vec2);
}

3)

#include <iostream>
using namespace std;

struct side
{
double area;
double diagonal;
};

side Square(const double &gverdi)


{

side data;
data.area = gverdi * gverdi;
data.diagonal = gverdi * sqrt(2);
return data;
}

double Square(const double& gverdi, double& fartobi)


{
fartobi = gverdi * gverdi;
return gverdi * sqrt(2);
}

int main()
{
double S, a;
cin >> a;
side c;
c = Square(a);
cout << "Diagonalia: " << c.diagonal << endl << "Fartobia: " << c.area << endl;
double b = 4.5;
double d = Square(b, S);
cout << "Diagonalia: " << d << endl << "Fartobia: " << S << endl;

}
4)

#include "iostream"
#include "fstream"
using namespace std;

class Car
{
public:
string name;
double xarji; //lari
double speed; //kilometri saatshi
double cost; //dolari
Car() {}
Car(string n, double x, double s, double c)
{
name = n;
xarji = x;
speed = s;
cost = c;
}
void printF()
{
cout << "Manqanis saxeli: " << name << endl;
cout << "100 kilometrze xarji larebshi: " << xarji << endl;
cout << "Sichqare: " << speed << endl;
cout << "Fasi: " << cost << endl;
}
};

int main()
{
Car cr1, cr2, cr3;
ifstream ifs("cars.txt");
ifs >> cr1.name >> cr1.xarji >> cr1.speed >> cr1.cost;
ifs >> cr2.name >> cr2.xarji >> cr2.speed >> cr2.cost;
ifs >> cr3.name >> cr3.xarji >> cr3.speed >> cr3.cost;
cr1.printF();
cr2.printF();
cr3.printF();
Car minX = cr1;
if (cr2.xarji < minX.xarji) minX = cr2;
if (cr3.xarji < minX.xarji) minX = cr3;
Car maxC = cr1;
if (cr2.cost > maxC.cost) maxC = cr2;
if (cr3.cost > maxC.cost) maxC = cr3;
Car* maxS = &minX;
if (maxC.speed > maxS->speed) maxS = &maxC;
ofstream ofs("fastest.txt");
ofs << "Manqanis saxelia: " << maxS->name << endl << "Xarjia: " << maxS->xarji << endl << "Sichqarea: " << maxS-
>speed << endl << "Fasi: " << maxS->cost << endl;

You might also like