Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //============================================================================
- // Name : Kolokwium.cpp
- // Author :
- // Version :
- // Copyright : Your copyright notice
- // Description : Hello World in C++, Ansi-style
- //============================================================================
- #include <iostream>
- #include <cstdlib>
- #include <string>
- using namespace std;
- float zad1(int tab[], int rozmiar)
- {
- float sred=0;
- for (int i=0; i<=rozmiar-1; i++)
- {
- sred=sred+tab[i];
- }
- sred=sred/rozmiar;
- float m1,m2;
- if (tab[0]<=sred)
- m1=sred-tab[0];
- else if (tab[0]>=sred)
- m1=tab[0]-sred;
- m2=tab[0];
- for (int i=1; i<=rozmiar-1; i++)
- {
- if (tab[i]>=sred && tab[i]-sred<=m1)
- {
- m1=tab[i]-sred;
- m2=i;
- }
- else if (tab[i]<sred && sred-tab[i]<=m1)
- {
- m1=sred-tab[i];
- m2=i;
- }
- }
- return m2;
- }
- void zad3(char tab[], char tab2[])
- {
- int rozmiar=strlen(tab);
- int j=0;
- for (int i=0; i<=rozmiar; i++)
- {
- tab2[j]=tab[i];
- j++;
- tab2[j]=' ';
- j++;
- }
- cout<<tab2<<endl;
- for (int i=0 ; i<=2*rozmiar; i++)
- {
- cout<<tab2[i];
- }
- }
- int zad2()
- {
- string cosd;
- cout<<"Wprowadz string: "<<endl;
- cin.sync();
- getline(cin,cosd);
- int buf=cosd.find(" ");
- if (buf<0)
- return 0;
- else if (buf>=0)
- return 1;
- }
- int main() {
- while(true)
- {
- int tab[]={100,2,3,4};
- cout<<"Wybierz zadanie:"<<endl;
- cout<<"1. Zadanie 1"<<endl;
- cout<<"2. Zadanie 2"<<endl;
- cout<<"3. Zadanie 3"<<endl;
- char tab2[100];
- int x;
- char wybor;
- cin>>wybor;
- if (wybor=='q' || wybor=='Q')
- exit(0);
- else
- {
- switch(wybor)
- {
- case '1': cout<<zad1(tab,4); break;
- case '2': cout<<zad2(); break;
- case '3': zad3("MITP",tab2); break;
- }
- }
- cout<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement