Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1.
- #include <iostream>
- using namespace std;
- namespace arytmetyczne
- {
- float dodaj(float a, float b)
- {
- return a+b;
- }
- float odejmij(float a, float b)
- {
- return a-b;
- }
- float pomnoz(float a, float b)
- {
- return a*b;
- }
- float podziel(float a, float b)
- {
- return a/b;
- }
- float modulo(int a, int b)
- {
- return a%b;
- }
- float wczytaj()
- {
- float a;
- cout << "Podaj liczbe: ";
- cin >> a;
- return a;
- }
- int float_to_int(float *a)
- {
- return *a;
- }
- }
- using namespace arytmetyczne;
- void kalkulator(float a, float b)
- {
- cout << "Dzialania"<<endl;
- cout << "a+b: "<< dodaj(a,b)<<endl;
- cout << "a-b: "<< odejmij(a,b)<<endl;
- cout << "a*b: "<< pomnoz(a,b)<<endl;
- cout << "a/b: "<< podziel(a,b)<<endl;
- cout << "a%b: "<< modulo(float_to_int(&a),float_to_int(&b))<<endl;
- }
- int main()
- {
- float a, b;
- cout << "Wczytywanie a"<<endl;
- a=wczytaj();
- cout << "Wczytywanie b"<<endl;
- b=wczytaj();
- cout << endl;
- kalkulator(a,b);
- return 0;
- }
- 2.
- #include <iostream>
- #include <conio.h>
- using namespace std;
- int norma(int **t, int n, int m, int b=119)
- {
- if(b==119)
- {
- int maxi=0;
- for(int i=0; i<m; i++)
- {
- int norma=0;
- for(int j=0; j<n; j++)
- {
- norma += t[j][i];
- }
- if(norma>maxi)
- maxi=norma;
- }
- return maxi;
- }
- else
- {
- int maxi=0;
- for(int i=0; i<n; i++)
- {
- int norma=0;
- for(int j=0; j<m; j++)
- {
- norma+=t[i][j];
- }
- if(norma>maxi)
- maxi=norma;
- }
- return maxi;
- }
- }
- void podaj_wielkosc(int *n, int *m)
- {
- cout << "Podaj ilosc wierszy: ";
- cin >> *n;
- cout << "Podaj ilosc kolumn: ";
- cin >> *m;
- }
- void podaj_tablice(int **t, int n, int m)
- {
- for(int i=0; i<m; i++)
- for(int j=0; j<n; j++)
- {
- cout << "["<<i+1<<"]["<<j+1<<"]: ";
- cin >> t[i][j];
- }
- }
- int main()
- {
- int n,m;
- int **tab;
- podaj_wielkosc(&n, &m);
- tab = new int*[m];
- for(int i=0; i<m; i++)
- tab[i]= new int[n];
- podaj_tablice(tab, n,m);
- int wybor;
- cout << "Mam liczyc z wierszy(w) czy z kolumn(k)?? ";
- wybor=getch();
- cout << endl;
- if(wybor==119||wybor==107)
- {
- cout << "Norma: "<<norma(tab, n, m, wybor);
- }
- else
- {
- cout << "Norma: "<<norma(tab, n, m);
- }
- return 0;
- }
- 3.
- #include <iostream>
- using namespace std;
- #include "drugi.h"
- int main()
- {
- int n;
- towary *t;
- cin >> n;
- t = new towary[n];
- w_tablica(n, t);
- wypisz_nazwa(n, t);
- wypisz_naj(n, t);
- return 0;
- }
- h.
- struct towary
- {
- string nazwa;
- string dostawca;
- float cena;
- };
- void w_tablica(int n, towary *t)
- {
- for(int i=0; i<n; i++)
- {
- cin >> t[i].nazwa;
- cin >> t[i].dostawca;
- cin >> t[i].cena;
- }
- }
- void wypisz_nazwa(int n, towary *t)
- {
- string nazwa;
- cin >> nazwa;
- for(int i=0; i<n; i++)
- if(t[i].nazwa==nazwa)
- cout << t[i].nazwa<<" "<<t[i].dostawca<<" "<<t[i].cena<<endl;
- }
- void wypisz_naj(int n, towary *t)
- {
- string nazwa;
- cin >> nazwa;
- float najmiejsza=1000000;
- int naj;
- for(int i=0; i<n; i++)
- if(t[i].nazwa==nazwa&&najmiejsza>t[i].cena)
- naj = i;
- cout << t[naj].nazwa<<" "<<t[naj].dostawca<<" "<<t[naj].cena;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement