Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1.
- ---------------
- #include <iostream>
- #include <cstring>
- using namespace std;
- class Vraboten
- {
- private:
- char ime[20];
- char prezime[20];
- int plata;
- char pol [10];
- public:
- Vraboten () {}
- Vraboten (char *i, char *pr, char *pol, int pl)
- {
- strcpy(ime,i);
- strcpy(prezime,pr);
- strcpy(this->pol,pol);
- plata = pl;
- }
- friend ostream& operator<< (ostream &x,const Vraboten &v)
- {
- x << v.ime <<" "<< v.prezime <<" "<< v.pol;
- x <<" "<< v.plata << endl;
- return x;
- }
- void setIme (char *ime)
- {
- strcpy(this->ime,ime);
- }
- void setPrezime (char *pr)
- {
- strcpy(prezime,pr);
- }
- void setPlata (int k)
- {
- plata = k;
- }
- void setPol (char *p)
- {
- strcpy(pol,p);
- }
- char *getPrezime ()
- {
- return prezime;
- }
- char *getIme ()
- {
- return ime;
- }
- char *getPol ()
- {
- return pol;
- }
- int getPlata ()
- {
- return plata;
- }
- };
- int main ()
- {
- int n, suma = 0, k = 0;
- cout << "Vnesete broj na vraboteni"<<endl;
- cin >> n;
- Vraboten firma [n];
- cout << "Vnesete ime, prezime, pol, plata na sekoj rabotnik "<<endl;
- for (int i=0; i<n; i++)
- {
- char ime[20];
- char prezime[20];
- int plata;
- char pol [10];
- cin >> ime >> prezime >> pol >> plata;
- firma [i] = Vraboten (ime,prezime,pol,plata);
- suma += firma [i].getPlata();
- if(strcmp(firma[i].getPol(),"maski") == 0) k++;
- }
- cout<<"Vo firmata ima " << k << " vraboten/i od maski pol"<<endl;
- cout<<"Prosecnata plata vo firmata e " << (float)suma/n <<endl;
- int flag = 1;
- for(int i=0; i<n; i++)
- {
- if(strcmp(firma[i].getPrezime(),"Mitrevski")==0)
- {
- if(flag)
- {
- cout<<"Vraboteni so prezime Mitrevski: "<<endl;
- flag = 0;
- }
- cout<<firma[i];
- }
- }
- if(flag) cout<<"Nema vraboteni so prezime Mitrevski"<<endl;
- return 0;
- }
- -----------------------------------------------------------------------------------------------------------------------
- 2.
- ---------------
- #include <iostream>
- #include <cstring>
- #include <cmath>
- using namespace std;
- class Vektor
- {
- private:
- int x;
- int y;
- int z;
- public:
- Vektor (int a = 0, int b = 0, int c = 0)
- {
- x = a;
- y = b;
- z = c;
- }
- Vektor (const Vektor &v)
- {
- x = v.x;
- y = v.y;
- z = v.z;
- }
- double Dolzina ()
- {
- return sqrt(x*x + y*y + z*z);
- }
- };
- int main ()
- {
- return 0;
- }
- --------------------------------------------------------------------------------------------------------------
- 3.
- -----------------------
- #include <iostream>
- #include <cstring>
- using namespace std;
- class Karakter
- {
- private:
- char *niza;
- public:
- Karakter ()
- {
- niza = new char [0];
- }
- Karakter (char *niza)
- {
- this->niza = new char[strlen(niza)+1];
- strcpy(this->niza,niza);
- }
- Karakter& operator = (const Karakter &k)
- {
- if(this != &k)
- {
- delete [] niza;
- niza = new char[strlen(k.niza)+1];
- strcpy(niza,k.niza);
- }
- return *this;
- }
- ~Karakter ()
- {
- delete [] niza;
- }
- char operator [] (int i)
- {
- return niza[i];
- }
- int getDolzina ()
- {
- return strlen(niza);
- }
- };
- int main ()
- {
- Karakter niza[10];
- niza[0]=Karakter("FINKI");
- cout<<niza[0].getDolzina()<<endl;
- return 0;
- }
- ------------------------------------------------------------------------------------------------------------------
- 4.
- #include <iostream>
- #include <cstring>
- using namespace std;
- class Proizvod{
- private:
- char ime[20];
- int sif_pr;
- int kolicina;
- int cena;
- public:
- Proizvod(){}
- Proizvod(char ime[], int sif_pr, int kolicina, int cena){
- strcpy(this->ime,ime);
- this->sif_pr=sif_pr;
- this->kolicina=kolicina;
- this->cena=cena;
- }
- void setIme(char ime[]){
- strcpy(this->ime,ime);
- }
- void setSifra(int sif_pr){
- this->sif_pr=sif_pr;
- }
- void setKolicina(int kolicina){
- this->kolicina=kolicina;
- }
- void setCena(int cena){
- this->cena=cena;
- }
- char *getIme(){
- return ime;
- }
- int getSifra(){
- return sif_pr;
- }
- int getKolicina(){
- return kolicina;
- }
- int getCena(){
- return cena;
- }
- friend ostream &operator<<(ostream &out, Proizvod &p){
- out<<p.ime<<" "<<p.sif_pr<<" "<<p.kolicina<<" "<<p.cena<<endl;
- return out;
- }
- ~Proizvod(){}
- };
- float prosecnaCena(Proizvod Prodavnica[], int n){
- float prosek=0.00;
- for(int i=0;i<n;i++){
- prosek+=Prodavnica[i].getCena();
- }
- return prosek/n;
- }
- int main(){
- Proizvod Prodavnica[100];
- int n, sum=0;
- cout<<"Vnesete broj na prodavnici"<<endl;
- cin>>n;
- cout<<"Vnesete gi karakteristikite na proizvodite\n"<<endl;
- for(int i=0;i<n;i++){
- char ime[20];
- int sifra;
- int kolicina;
- int cena;
- cin>>ime>>sifra>>kolicina>>cena;
- Prodavnica[i]=Proizvod(ime,sifra,kolicina,cena);
- if(Prodavnica[i].getSifra()==123){
- sum++;
- }
- }
- cout<<"Prosecnata cena e: "<<prosecnaCena(Prodavnica, n);
- for(int i=0;i<n;i++){
- {
- for (int j =0 ;j<n;j++)
- {
- if(Prodavnica[i].getCena()>Prodavnica[i].getCena()){
- Proizvod temp=Prodavnica[j];
- Prodavnica[j]=Prodavnica[j+1];
- Prodavnica[j+1]=temp;
- }
- }
- }
- for(int i=0;i<n;i++){
- cout<<Prodavnica[i];
- }
- return 0;
- }
- }
- ------------------------
- ----------------------------------------------------------------------------------------------
- 7. pod A
- 8. pod B
- 10. pod A
- 11.Promenlivata bpub ne mozhi da se pristapi bidejki se naogja vo Parrent klasata a se povikuva vo Child. (samo obratnoto), isto taka vo klasata PrivDerived nemashe zagrada ( }; ) pa i to kako greshka :D
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement