Compare commits
2 Commits
095e7c102c
...
48083a47de
| Author | SHA1 | Date | |
|---|---|---|---|
|
48083a47de
|
|||
|
3f67343476
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
19
Laboratorium/20221130155128/czytanie.cpp
Normal file
19
Laboratorium/20221130155128/czytanie.cpp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
int czytaj(char *nazwa){
|
||||||
|
ifstream plik(nazwa);
|
||||||
|
string linia;
|
||||||
|
while (getline(plik, linia)) {
|
||||||
|
std::cout << linia << std::endl;
|
||||||
|
}
|
||||||
|
plik.close();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int main (int argc, char *argv[])
|
||||||
|
{
|
||||||
|
czytaj(argv[1]);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
17
Laboratorium/20221130155128/generowanie.cpp
Normal file
17
Laboratorium/20221130155128/generowanie.cpp
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
int generator(int n, char *nazwa){
|
||||||
|
ofstream plik(nazwa);
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
plik << i << endl;
|
||||||
|
}
|
||||||
|
plik.close();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int main (int argc, char *argv[])
|
||||||
|
{
|
||||||
|
generator(atoi(argv[1]), argv[2]);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user