Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Ernest Bursa 2010
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <iostream>
- using namespace std;
- // Maksimum
- float max(int t[], int n){
- float max = (float)t[0];
- for(int i = 1; i < n; i++)
- if(t[i]>max)
- max = (float)t[i];
- return max;
- }
- // Minimum
- float min(int t[], int n){
- int min = (float)t[0];
- for(int i = 1; i < n; i++)
- if(t[i]<min)
- min = (float)t[i];
- return min;
- }
- // Średnia
- float avg(int t[], int n){
- float avg = 0;
- for(int i=0;i<n;i++){
- avg += (float)t[i];
- }
- avg = avg/(float)n;
- return avg;
- }
- // Suma
- float sum(int t[], int n){
- float sum = (float)0;
- for(int i = 0; i<n; i++)
- sum+=(float)t[i];
- return sum;
- }
- // Statystyki
- void staty(int t[], int n, float *maxi, float *mini, float *sumi, float *avgi){
- *maxi = max(t, n);
- *mini = min(t, n);
- *sumi = sum(t, n);
- *avgi = avg(t, n);
- }
- // Suma macierzy
- void sum_matrix(int m, int n, int **matrix1, int **matrix2, int **matrix3){
- for(int i = 0; i<m; i++)
- for(int j = 0; j<n; j++)
- matrix1[i][j] = matrix2[i][j] + matrix3[i][j];
- }
- // Odejmowanie macierzy
- void minus_matrix(int m, int n, int **matrix1, int **matrix2, int **matrix3){
- for(int i=0; i < m; i++)
- for(int j=0; j < n; j++)
- matrix1[i][j] = matrix2[i][j]-matrix3[i][j];
- }
- // Mnożenie macierzy
- void multi_matrix(int m, int n, int **matrix1, int **matrix2, int **matrix3){
- for(int i=0; i<m; i++)
- for(int j=0; j<n; j++)
- matrix1[i][j] = matrix2[i][j]*matrix3[i][j];
- }
- // ToDo: Wczytywanie wektora
- void read_vector(int *vector){
- int n, tmp_value;
- cout << "Wprowadz dlugosc wektora: ";
- cin >> n;
- cout << "\nWprowadz kolejno wartosci wektora: ";
- for(int i=0; i<n;i++){
- cin >> tmp_value;
- vector[i] = tmp_value;
- }
- }
- // ToDo: Wczytywanie macierzy
- void read_matrix(int **matrix){
- int m,n, tmp_value;
- cout << "Podaj wymiar m: ";
- cin >> m;
- cout << "\nPodaj wymiar n: ";
- cin >> n;
- for(int i=0; i<n; i++)
- matrix[i] = new int[n];
- for(int i=0; i<m; i++){
- for(int j=0; j<n; j++){
- cout << "Wprowadz wartosc: ";
- cin >> tmp_value;
- matrix[i][j] = tmp_value;
- cout << "\n";
- }
- }
- }
- // Wyświetlanie wczytanego wektora
- void display_vector(int t[], int n){
- cout << "Wyswietlam wczytany wektor: [";
- for(int i=0; i<n; i++){
- cout << t[i];
- if(i!=(n-1))
- cout << ", ";
- }
- cout << "]";
- }
- // Wyświetlanie wczytanej macierzy
- void display_matrix(int m, int n, int **matrix1){
- cout << "Wyświetlam wczytaną macierz: [";
- for(int i=0; i<m; i++){
- for(int j=0; j<n; j++){
- cout << matrix1[i][j];
- if(j!=(n-1))
- cout << ", ";
- }
- cout << "\n";
- }
- }
- int main(int argc, char**argv)
- {
- bool loop = 1;
- while(loop){
- cout << "| Menu: \n";
- cout << "- [1] - Min \n";
- cout << "- [2] - Max \n";
- cout << "- [3] - Avg \n";
- cout << "- [4] - Statystyka \n";
- cout << "- [5] - Suma macierzy \n";
- cout << "- [6] - Odejmowanie macierzy \n";
- cout << "- [7] - Mnozenie macierzy \n";
- cout << "-----------------------------------\n";
- cout << "Na dobry poczatek wylosowalem tablice [";
- int n = 5;
- int *tablica = new int[n];
- for(int i=0; i<n; i++){
- tablica[i] = rand() % 25 + 3;
- cout << tablica[i];
- if(i+1!=n)
- cout << ", ";
- }
- // Można alternatywnie użyć gotowej funkcji display_vector()
- cout << "]\n-----------------------------------\n";
- cout << "\n Wybierz opcje nr: ";
- int input;
- cin >> input;
- cout << "\n\n";
- switch(input){
- case 1:
- cout << "Min: " << min(tablica, n) << "\n";
- break;
- case 2:
- cout << "Max: " << max(tablica, n) << "\n";
- break;
- case 3:
- cout << "Avg: " << avg(tablica, n) << "\n";
- break;
- case 4:
- cout << "Statystyka: ";
- float maxi, mini, sumi, avgi;
- staty(tablica, n, &maxi, &mini, &sumi, &avgi);
- cout << "Min: " << mini << "\n";
- cout << "Max: " << maxi << "\n";
- cout << "Suma: " << sumi << "\n";
- cout << "Avg: " << avgi << "\n";
- break;
- case 5: // Suma macierzy
- break;
- case 6: // Odejmowanie macierzy
- break;
- case 7: // Mnozenie macierzy
- break;
- default:
- loop = 0;
- break;
- }
- cout << "\n-----------------------------------\n";
- }
- cin.get();
- return 0;
- }
Add Comment
Please, Sign In to add comment