PR I - Code Predavanje Fukcije (ukljuciti sva tri file-a u projekat)
Tekst dokumenta166 redova
- == fukncije.cpp
- #include "stdafx.h"
- #include <iostream>
- #include "funkcije.h"
- int nekaNovaFunkcija(int &a, int &b) //sabira sve brojeve izmedju a i b ukljucujuci i njih
- {
- int rezultat=0;
- for(int i=a; i<=b; i++)
- {
- rezultat+=i;
- }
- return rezultat;
- }
- == funkcije.h
- #ifndef FUNKCIJE
- #define FUNKCIJE
- int nekaNovaFunkcija(int&, int&);
- #endif
- == PredavanjeFunkcije.cpp
- // PredavanjeFunkcije.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include "funkcije.h"
- #include <iostream>
- using namespace std;
- int a=5,b=3;
- bool isBinarni(int);
- int mnozenje(); //deklaracija
- int povrs_pravoug(int stranica1, int stranica2); //moze i int povrs_pravoug(int, int);
- int faktorijel (int); //poziv po vrijednosti
- void na_cetvrtu (int&); //poziv po referenci
- //privremeno ovako definisemo
- void sabiranje()
- {
- int c;
- c = a+b;
- a++;
- cout<< "Rezultat sabiranja je: "<<c<<endl;
- cout<<a<<endl;
- }
- int oduzimanje()
- {
- int c;
- c = a-b;
- //cout<< "Rezultat oduzimanja je: "<<c<<endl;
- return c;
- }
- void main()
- {
- int broj;
- cout << "Unesite broj: ";
- cin >> broj;
- if (isBinarni(broj) == true)
- cout << "Broj je binarni.";
- else
- cout << "Broj nije binarni. ";
- //int rez;
- // sabiranje();
- // cout<<a<<endl;
- // rez=oduzimanje();
- // cout<< "Rezultat oduzimanja je: "<<rez<<endl;
- // rez=mnozenje();
- // cout<< "Rezultat mnozenja je: "<<rez<<endl;
- /*
- int strA =5, strB=4;
- rez=povrs_pravoug(strA, strB);
- cout<< "Povrsina pravougaonika je: "<<rez<<endl;
- */
- /*
- //poziv po vrijednosti
- int neki_br=5, neki_rez;
- cout<<neki_br<<endl;
- neki_rez = faktorijel(neki_br);
- cout<<neki_br<<endl;
- cout<<neki_rez<<endl;
- */
- /*
- //poziv po referenci
- int neki_br=2;
- cout<<neki_br<<endl;
- na_cetvrtu(neki_br);
- cout<<neki_br<<endl;
- */
- //poziv iz odvojenog .cpp file ukljucivanjem vlastite biblioteke
- //int brA=5, brB=17, c;
- //c=nekaNovaFunkcija(brA,brB);
- //cout<<c<<endl;
- system("pause");
- //return 0; // ne treba return
- }
- int mnozenje() //definicja
- {
- int c;
- c = a*b;
- //cout<< "Rezultat mnozenja je: "<<c<<endl;
- return c;
- }
- int povrs_pravoug(int stranica1, int stranica2)
- {
- return stranica1*stranica2;
- }
- void na_cetvrtu (int &broj)
- {
- for (int i = 1; i<=2;i++)
- {
- broj*=broj;
- }
- }
- int faktorijel (int broj)
- {
- int rezult=1;
- for (int i=1; i<=broj; i++)
- {
- rezult*=i;
- }
- return rezult;
- }
- bool isBinarni(int broj)
- {
- bool isB = true;
- int cifra, kopija = broj;
- while (kopija != 0)
- {
- cifra = kopija % 10;
- if (cifra > 1)
- {
- isB = false;
- break;
- }
- kopija /= 10;
- }
- if (isB==false)
- {
- return false;
- }
- else
- {
- return true;
- }
- }