problema 7
Se foloseste struct
Majoritatea stiu sa fac, dar nu-mi dau seama cum le grupez
Răspunsuri la întrebare
#include <iostream>
using namespace std;
struct punct {
int x;
int y;
int cadran;
};
int main()
{
int n = 0;
cout << "Introduceti numarul de puncte: ";
cin >> n;
punct p[100];
cout << endl;
for (int i = 0; i < n; i++)
{
cout << "Punctul " << i+1 << ":" << "\n";
cout << "x = ";
cin >> p[i].x;
cout << "y = ";
cin >> p[i].y;
if (p[i].x == 0 && p[i].y == 0) { p[i].cadran = 0; }
else if (p[i].x >= 0 && p[i].y >= 0) { p[i].cadran = 1; }
else if (p[i].x <= 0 && p[i].y >= 0) { p[i].cadran = 2; }
else if (p[i].x <= 0 && p[i].y <= 0) { p[i].cadran = 3; }
else if (p[i].x >= 0 && p[i].y <= 0) { p[i].cadran = 4; }
cout << endl;
}
cout << "Punctele din origine: \n";
for(int i = 0; i < n; i++)
{
if (p[i].cadran == 0)
{
cout << "(" << p[i].x << ", " << p[i].y << ")" << "\n";
}
}
cout << "\nPunctele din cadranul I: \n";
for (int i = 0; i < n; i++)
{
if (p[i].cadran == 1)
{
cout << "(" << p[i].x << ", " << p[i].y << ")" << "\n";
}
}
cout << "\nPunctele din cadranul II: \n";
for (int i = 0; i < n; i++)
{
if (p[i].cadran == 2)
{
cout << "(" << p[i].x << ", " << p[i].y << ")" << "\n";
}
}
cout << "\nPunctele din cadranul III: \n";
for (int i = 0; i < n; i++)
{
if (p[i].cadran == 3)
{
cout << "(" << p[i].x << ", " << p[i].y << ")" << "\n";
}
}
cout << "\nPunctele din cadranul IV: \n";
for (int i = 0; i < n; i++)
{
if (p[i].cadran == 4)
{
cout << "(" << p[i].x << ", " << p[i].y << ")" << "\n";
}
}
}