Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Napišite program u kojem ćete korisniku omogućiti da unese i ispiše elemente niza
- različitih tipova, te da pronađe najmanji element u nizu. Omogućite korisniku da sam
- odluči o broju elemenata niza, te da izabere između:
- - niza cijelih brojeva
- - niza realnih brojeva
- - niza karaktera
- Upotrijebite predloške funkcija.
- */
- #ifdef _MSC_VER
- #define _CRT_SECURE_NO_WARNINGS
- #endif
- #include <iostream>
- using namespace std;
- char crt[] = "\n--------------------------------------------------\n";
- template <class T>
- void unos(T niz[], int max)
- {
- cout << crt;
- for (size_t i = 0; i < max; i++)
- {
- cout << i + 1 << " -> ";
- cin >> niz[i];
- }
- }
- template <class T>
- void ispis(T niz[], int max){
- for (int i = 0; i < max; i++)
- {
- cout << niz[i] << "\t";
- }
- cout << crt;
- }
- template <class T>
- T najmanjiunizu(T niz[], int max){
- T * naj = &niz[0];
- for (int i = 1; i < max; i++){
- if (niz[i] < *naj)
- naj = &niz[i];
- }
- return *naj;
- }
- int main() {
- int max;
- char izbor;
- cout << "Koliko elemenata ce imati niz: ";
- cin >> max;
- cout << "c- char; i - int; f - float" << endl;
- cin >> izbor;
- switch (izbor){
- case 'c':
- case 'C':
- {
- char * pok = new char[max];
- cout << "Unesi elemente niza: ";
- unos(pok, max);
- cout << crt << "Vas niz je: " << crt;
- ispis(pok, max);
- cout << crt << "Najmanji clan niza je: " << najmanjiunizu(pok,max);
- delete pok;
- pok = nullptr;
- break;
- }
- case 'i':
- case 'I':
- {
- int * pok = new int[max];
- cout << "Unesi elemente niza: ";
- unos(pok, max);
- cout << crt << "Vas niz je: " << crt;
- ispis(pok, max);
- cout << crt << "Najmanji clan niza je: " << najmanjiunizu(pok, max);
- delete pok;
- pok = nullptr;
- break;
- }
- case 'f':
- case 'F':
- {
- float * pok = new float[max];
- cout << "Unesi elemente niza: ";
- unos(pok, max);
- cout << crt << "Vas niz je: " << crt;
- ispis(pok, max);
- cout << crt << "Najmanji clan niza je: " << najmanjiunizu(pok, max);
- delete pok;
- pok = nullptr;
- break;
- }
- }
- system("pause>null");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement