-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dodanie kodów cpp i usunięcie arkusza
- Loading branch information
Showing
10 changed files
with
605 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#include <iostream> | ||
#include <cstdio> | ||
#include <cstdlib> | ||
|
||
using namespace std; | ||
|
||
class Czas { | ||
public: | ||
//Czas(); //konstruktor | ||
Czas(int=0, int=0, int=0); | ||
void ustawCzas(int,int,int); //ustawia godz.,min. i sek. | ||
void drukujWojskowy(); //wyświetla czas w formacie wojskowym | ||
void drukujStandardowy(); //wyświetla czas w formacie wojskowym | ||
void drukujLicznik(); | ||
void impuls(int); | ||
~Czas(); //dekonstruktor | ||
static int licznik; | ||
private: | ||
int godz; | ||
int min; | ||
int sek; | ||
}; | ||
/* | ||
Czas::Czas() { | ||
godz = min = sek = 0; | ||
cout << "\nKonstruktor obiektu typu Czas" << endl; | ||
} | ||
*/ | ||
|
||
int Czas::licznik = 0; | ||
|
||
Czas::Czas(int g, int m, int d) { | ||
ustawCzas(g,m,d); | ||
licznik++; | ||
cout << "\nKonstruktor parametryczny obiektu typu Czas" << endl; | ||
} | ||
|
||
Czas::~Czas() { | ||
cout << "Dekonstruktor obiektu typu Czas" << endl; | ||
} | ||
|
||
void Czas::ustawCzas(int g, int m, int s) {//fun. typu ustaw | ||
godz = (g >= 0 && g < 24) ? g : 0; | ||
min = (m >= 0 && m < 60) ? m : 0; | ||
sek = (s >= 0 && s < 60) ? s : 0; | ||
} | ||
|
||
void Czas::drukujWojskowy() { | ||
cout << (godz < 10 ? "0" : "") << godz << ":" | ||
<< (min < 10 ? "0" : "") << min; | ||
} | ||
|
||
void Czas::drukujStandardowy() { | ||
cout << ((godz == 0 || godz == 12) ? 12 : godz % 12) | ||
<< ":" << (min < 10 ? "0" : "") << min | ||
<< ":" << (sek < 10 ? "0" : "") << sek | ||
<< (godz < 12 ? " AM" : " PM"); | ||
} | ||
|
||
void Czas::drukujLicznik() { | ||
cout << "\nIlość obiektów: " << licznik << "\n"; | ||
} | ||
|
||
void Czas::impuls(int sek) { | ||
; | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
Czas t; //tworzymy instancję klasy, czyli OBIEKT | ||
Czas t2(24,12,12); | ||
cout << "Czas (początkowy) wojskowy: " << endl; | ||
t.drukujWojskowy(); | ||
cout << "\nCzas (początkowy) standardowy: " << endl; | ||
t.drukujStandardowy(); | ||
t.ustawCzas(11,2,59); | ||
cout << "\n"; | ||
t.drukujStandardowy(); | ||
cout << "\n"; | ||
t2.drukujStandardowy(); | ||
cout << "\n"; | ||
cout << "Ilość obiektów: " << Czas::licznik << endl; | ||
t.drukujLicznik(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include <iostream> | ||
#include <cstdio> | ||
#include <cstdlib> | ||
#include <cstring> | ||
|
||
using namespace std; | ||
|
||
class Figura { | ||
public: | ||
Figura(char figura); //konstruktor | ||
void getNazwa(); //wyświetl nazwę figury | ||
char getTyp(); //zwraca typ figury | ||
void getPole(); //wyświetl pole figury | ||
void getObwod(); //wyświetl obwód figury | ||
private: | ||
char typ; //litera oznaczająca figurę | ||
char nazwa[15]; //nazwa figury | ||
float pole; //pole figury | ||
float obwod; //obwód figury | ||
void setTyp(char figura); | ||
}; | ||
|
||
Figura::Figura(char figura) { | ||
setTyp(figura); | ||
cout << "Utworzono: "; | ||
getNazwa(); | ||
cout << endl; | ||
pole = obwod = 0; | ||
} | ||
|
||
void Figura::setTyp(char figura) { | ||
switch (figura) { | ||
case 'k': strcpy(nazwa,"kwadrat"); typ = figura; break; | ||
case 'p': strcpy(nazwa,"prostokąt"); typ = figura; break; | ||
case 't': strcpy(nazwa,"trójkąt"); typ = figura; break; | ||
case 'o': strcpy(nazwa,"koło"); typ = figura; break; | ||
default: | ||
cout << "Nieznany typ figury!"; | ||
strcpy(nazwa,"kwadrat"); typ = 'k'; | ||
} | ||
} | ||
|
||
char Figura::getTyp() { return typ; } | ||
void Figura::getNazwa() { cout << nazwa; } | ||
void Figura::getPole() { cout << pole; } | ||
void Figura::getObwod() { cout << obwod; } | ||
|
||
int main(int argc, char *argv[]) { | ||
char odp; | ||
cout << "Wybierz figurę: " << endl; | ||
cout << " k - kwadrat\n p - prostokąt \n t - trójkąt \n o - koło\n"; | ||
cin >> odp; | ||
Figura f1(odp); | ||
Figura f2('t'); | ||
Figura f3('x'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include <iostream> | ||
#include <cstdio> | ||
#include <cstdlib> | ||
|
||
using namespace std; | ||
|
||
struct elem_listy { | ||
int liczba; //dane przechowywane w el. listy | ||
elem_listy *nast; //wskaźnik do następnego elementu listy | ||
}; | ||
|
||
int main(int argc, char *argv[]) { | ||
elem_listy *glowa = NULL; //tworzymy listę pustą | ||
elem_listy *nowy; | ||
|
||
char odp; | ||
int d; | ||
|
||
cout << "Czy dodasz element do listy? (t/n) "; | ||
cin >> odp; | ||
while (odp != 'n') { | ||
cout << "Podaj liczbę: "; | ||
cin >> d; | ||
|
||
try { | ||
nowy = new elem_listy; | ||
} catch (bad_alloc) { | ||
cout << "Brak pamięci!"; | ||
break; | ||
} | ||
|
||
nowy->nast = glowa; | ||
nowy->liczba = d; | ||
|
||
glowa = nowy; | ||
|
||
cout << "Czy dodasz kolejny element? (t/n) "; | ||
cin >> odp; | ||
} | ||
|
||
elem_listy *tmp = glowa; | ||
cout << "Oto lista: " << endl; | ||
while (tmp != NULL) { | ||
cout << tmp->liczba << " "; | ||
tmp = tmp->nast; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include <iostream> | ||
#include <cstdio> | ||
#include <cstdlib> | ||
|
||
using namespace std; | ||
|
||
struct el_listy { | ||
int liczba; | ||
el_listy *nast; | ||
}; | ||
|
||
char czy() { | ||
char odp; | ||
cout << "Następny? (t/n)"; | ||
cin >> odp; | ||
return odp; | ||
} | ||
|
||
int getDane() { | ||
int d; | ||
cout << "Podaj liczbę: "; | ||
cin >> d; | ||
return d; | ||
} | ||
|
||
void drukuj(el_listy *glowa) { | ||
el_listy *tmp; | ||
tmp = glowa; | ||
while (tmp != NULL) { | ||
cout << tmp->liczba << " "; | ||
tmp = tmp->nast; | ||
} | ||
cout << endl; | ||
} | ||
|
||
int addToB() { | ||
el_listy *glowa = NULL; | ||
el_listy *ogon = NULL; | ||
el_listy *nowy; | ||
|
||
while(czy() != 'n') { | ||
try { | ||
nowy = new el_listy; //tworzenie nowego el. listy | ||
} catch(bad_alloc) { | ||
cout << "Za mało!"; | ||
return 1; | ||
} | ||
nowy->liczba = getDane(); | ||
nowy->nast=NULL; | ||
if (glowa == NULL) {//lista nie ma elementów | ||
glowa = nowy; //wykona się tylko raz; | ||
ogon = glowa; | ||
} else { | ||
ogon->nast = nowy; | ||
ogon = nowy; | ||
} | ||
} | ||
|
||
drukuj(glowa); | ||
|
||
return 0; | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
int wynik=0; | ||
wynik=addToB(); | ||
return wynik; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <cstdlib> | ||
#include <iostream> | ||
#include <cmath> | ||
|
||
using namespace std; | ||
|
||
int main(int argc, char *argv[]) { | ||
double a, b; // zmienne pomocnicze - wsp��rzedne losowanego punktu | ||
long T = 0; // dzi�ki typowi long mo�emy losowac wiele punkt�w | ||
long R; | ||
long ilosc; | ||
srand(time(NULL)); // inicjacja funkcji rand() | ||
cout << "Na podstawie ilu punktow znalezc wartosc liczby pi? "; | ||
cin >> ilosc; | ||
for(R=0; R<ilosc; R++) | ||
{ | ||
a = (double)rand()/(RAND_MAX); // losujemy liczby rzeczywiste | ||
b = (double)rand()/(RAND_MAX); // z zakresu <0,1> | ||
if (a*a+b*b<=1) T++; // je�li punkt nale�y do ko�a to zwi�kszamy licznik | ||
} | ||
cout << "liczba pi ma wartosc : " << (double)(4*T)/R << endl; | ||
cout << "Liczba Pi: " << M_PI << endl; | ||
|
||
system("PAUSE"); | ||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#include <cstdlib> | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
const int N = 19; //liczba element˘w w sortowanym zbiorze | ||
|
||
void wypelnij(int tablica[], int n) | ||
{ | ||
for (int i=0; i<n; i++) | ||
tablica[i] = rand()%11; | ||
} | ||
|
||
void wyswietl(int tablica[], int n) | ||
{ | ||
for (int i=0; i<n; i++) | ||
cout << tablica[i] << " "; | ||
cout << endl; | ||
} | ||
|
||
void wyswietl2(int tablica[], int x, int y) | ||
{ | ||
for (int i=x; i<=y; i++) | ||
cout << tablica[i] << " "; | ||
cout << endl; | ||
} | ||
|
||
void Merge(int d[], int pocz, int kon) | ||
{ | ||
cout << "wejcie: Merge(" << pocz << "," << kon << "): "; | ||
wyswietl2(d,pocz,kon); | ||
int i, i1, i2, sr; | ||
int temp[N]; //tablica pomocnicza, do niej przepiszemy elementy tablicy d | ||
|
||
for (i=0; i<N;i++) | ||
temp[i] = d[i]; | ||
sr = (pocz+kon)/2; | ||
i = pocz; //indeks “wedrujacy” po tablicy d | ||
i1 = pocz; //indeks “wedrujacy” po pierwszej polowce tablicy temp | ||
i2 = sr+1; //indeks “wedrujacy” po drugiej polowce tablicy temp | ||
while (i1<=sr && i2<=kon) { | ||
if (temp[i1]<temp[i2]) { | ||
d[i] = temp[i1]; | ||
i1++; | ||
} else { | ||
d[i]=temp[i2]; | ||
i2++; | ||
} | ||
i++; | ||
} | ||
if (i1>sr) | ||
while (i2<=kon) { | ||
d[i] = temp[i2]; | ||
i2++; i++; | ||
} | ||
else | ||
while (i1<=sr) { | ||
d[i]=temp[i1]; | ||
i1++; i++; | ||
} | ||
cout << "wyjcie: "; | ||
wyswietl2(d,pocz,kon); | ||
} | ||
|
||
void MergeSort(int d[], int pocz, int kon) | ||
{ | ||
cout << "MergeSort(" << pocz << "," << kon << "): "; | ||
wyswietl2(d,pocz,kon); | ||
int sr; | ||
sr = (pocz+kon)/2; | ||
if (pocz<sr) | ||
MergeSort(d,pocz,sr); | ||
if (sr+1<kon) | ||
MergeSort(d,sr+1,kon); | ||
Merge(d,pocz,kon); | ||
} | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
int tab[20]; | ||
int tabt[] = {3,2,3,8,4,1}; | ||
int n = 6; | ||
srand(time(NULL)); | ||
wypelnij(tab,n); | ||
cout << "Tablica przed sortowaniem: " << endl; | ||
wyswietl(tabt,n); | ||
MergeSort(tabt,0,n-1); | ||
cout << "\n\nTablica po posortowaniu: " << endl; | ||
wyswietl(tabt,n); | ||
cout << endl; | ||
system("PAUSE"); | ||
return EXIT_SUCCESS; | ||
} |
Oops, something went wrong.