Zadania z labu 6
This commit is contained in:
51
Laboratorium/20221116155920/structs.cpp
Normal file
51
Laboratorium/20221116155920/structs.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
|
||||
struct pointInSpace {
|
||||
double xCoord;
|
||||
double yCoord;
|
||||
};
|
||||
|
||||
struct rectangle {
|
||||
pointInSpace SW;
|
||||
pointInSpace NE;
|
||||
};
|
||||
struct circle {
|
||||
pointInSpace centre;
|
||||
double radius;
|
||||
};
|
||||
double distance(pointInSpace a, pointInSpace b){
|
||||
return std::sqrt(std::pow(a.xCoord - b.xCoord, 2) + std::pow(a.yCoord - b.yCoord, 2));
|
||||
}
|
||||
double rectArea(rectangle caseInPoint){
|
||||
return (caseInPoint.NE.xCoord-caseInPoint.SW.xCoord) * (caseInPoint.NE.yCoord-caseInPoint.SW.yCoord);
|
||||
}
|
||||
|
||||
int biggerRect(rectangle a, rectangle b){
|
||||
return (rectArea(a) > rectArea(b)) ? rectArea(a) : rectArea(b);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char* argv[]){
|
||||
pointInSpace dot = {3.141592, 42.0};
|
||||
std::cout << dot.xCoord << std::endl << dot.yCoord << std::endl;
|
||||
|
||||
rectangle square = {0.0,0.0,20.0,20.0};
|
||||
std::cout << square.SW.xCoord << std::endl << square.SW.yCoord << std::endl << square.NE.xCoord << std::endl << square.NE.yCoord << std::endl;
|
||||
|
||||
circle wheel = {1.0,1.0,1.0};
|
||||
std::cout << wheel.centre.xCoord << std::endl << wheel.centre.yCoord << std::endl << wheel.radius << std::endl;
|
||||
|
||||
std::cout << distance({1.0,1.0},{3.0,1.0}) << std::endl;
|
||||
|
||||
std::cout << rectArea(square) << std::endl;
|
||||
|
||||
rectangle rect1 = {13.0,10.0,15.0,15.0};
|
||||
std::cout << biggerRect(square,rect1) << std::endl;
|
||||
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user