Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- struct Circle{
- float radius;
- float CenterX;
- float CenterY;
- };
- struct Vec
- {
- float x;
- float y;
- };
- struct Matrix{
- float a[3][3];
- };
- void intpart(float*);
- void intpart(float&);
- void change(float*);
- void change(float&);
- void move(Circle*,Vec*);
- void move(Circle&,Vec&);
- void multiply(Matrix*,float*);
- void multiply(Matrix&,float&);
- void intpart(float *a)
- {
- *a = int(*a);
- }
- void intpart(float &a)
- {
- a=int(a);
- }
- void change(float *a) {
- *a = -1 * (*a);
- }
- void change(float &a)
- {
- a=-1*a;
- }
- void move(Circle *a,Vec *b)
- {
- a->CenterX= a->CenterX + b->x;
- a->CenterY = a->CenterY+ b->y;
- }
- void move(Circle &a,Vec &b)
- {
- a.CenterX+=b.x;
- a.CenterY+=b.y;
- }
- void multiply(Matrix *a,float *b)
- {
- for(int i=0;i<3;i++)
- for(int j=0;j<3;j++)
- a->a[i][j] *= *b;
- }
- void multiply(Matrix &a,float &b)
- {
- for(int i=0;i<3;i++)
- for(int j=0;j<3;j++)
- a.a[i][j] *= b;
- }
- int main() {
- float num = 3.65;
- float &numRef = num;
- intpart(&num);
- intpart(numRef);
- std::cout << num << " " << numRef << std::endl;
- float num1 = -3.789;
- float num2 = 4.5;
- float &num2Ref = num2;
- change(&num1);
- change(num2Ref);
- std::cout << num1 << " " << num2 << std::endl;
- Circle k;
- k.radius = 4;
- k.CenterX = 5;
- k.CenterY = 6;
- Vec a;
- a.x = 2;
- a.y = 2;
- Circle &kRef = k;
- Vec &aRef = a;
- move(&k, &a);
- move(kRef,aRef);
- std::cout << k.CenterX << " " << k.CenterY << std::endl;
- std::cout << kRef.CenterX << " " << kRef.CenterY << std::endl;
- Matrix p, l;
- int v = 0;
- for (int i = 0; i < 3; i++)
- for (int j = 0; j < 3; j++) {
- p.a[i][j] = v;
- l.a[i][j] = v;
- v++;
- }
- float b = -3;
- multiply(&p, &b);
- for (int i = 0; i < 3; i++){
- for (int j = 0; j < 3; j++) {
- std::cout << p.a[i][j] << " ";
- }
- std::cout<<std::endl;
- }
- Matrix& lRef = l;
- float& bRef = b;
- multiply(lRef,bRef);
- for (int i = 0; i < 3; i++){
- for (int j = 0; j < 3; j++) {
- std::cout << l.a[i][j] << " ";
- }
- std::cout<<std::endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement