PROGRAMSKE KODE 1. stran



Kode si lahko skopirate in prilepite v beležko ali direktno v prevajalnik. Lahko pa si jih snamete s strani PROGRAMI v zip formatu, skupaj s programi, ki so v exe formatu.

Če v kodah ali programih odkrijete kakšne nepravilnosti, mi prosim to sporočite po e-mailu:  moj e-mail

Seznam kod na tej strani:

Bankovci.cpp
Color_text.cpp
Delit2stevil.cpp
Elipsa.cpp
IZ3_SLO.cpp
TicTacToe.cpp (Križci in krožci)
Poraba_goriva.cpp
SIT2EVRE.cpp
sieve.cpp - Sito za praštevila
board1.cpp, board.h, game.cpp - štiri v vrsto
Hangman.cpp, vislice_seznam_besed.txt - Vislice
Business Card Program.cpp - Vizitka


Bankovci.cpp:


#include <iostream.h>

int main ()
{
	int vsota, deset_t, pet_t, tisoc, pet_s, dve_s, sto, pet_d, dvajset, deset, pet, ena;
	char odg;
	
	do
	{
	cout <<"vsota, ki jo zelite placati:"<<endl;
	cin >>vsota;
	if (vsota > 10000)
	{
		deset_t = vsota / 10000;
		vsota = vsota % 10000;
		cout <<"stevilo bankovcev po 10000 je "<<deset_t<<endl;
	}
	if (vsota > 5000)
	{
		pet_t = vsota / 5000;
		vsota = vsota % 5000;
		cout <<"stevilo bankovcev po 5000 je "<<pet_t<<endl;
	}
	if (vsota > 1000)
	{
		tisoc = vsota / 1000;
		vsota = vsota % 1000;
		cout <<"stevilo bankovcev po 1000 je "<<tisoc<<endl;
	}
	if (vsota > 500)
	{
		pet_s = vsota / 500;
		vsota = vsota % 500;
		cout <<"stevilo bankovcev po 500 je "<<pet_s<<endl;
	}
	if (vsota > 200)
	{
		dve_s = vsota / 200;
		vsota = vsota % 200;
		cout <<"stevilo bankovcev po 200 je "<<dve_s<<endl;
	}
	if (vsota > 100)
	{
		sto = vsota / 100;
		vsota = vsota % 100;
		cout <<"stevilo bankovcev po 100 je "<<sto<<endl;
	}
	if (vsota > 50)
	{
		pet_d = vsota / 50;
		vsota = vsota % 50;
		cout <<"stevilo bankovcev po 50 je "<<pet_d<<endl;
	}
	if (vsota > 20)
	{
		dvajset = vsota / 20;
		vsota = vsota % 20;
		cout <<"stevilo bankovcev po 20 je "<<dvajset<<endl;
	}
	if (vsota > 10)
	{
		deset = vsota / 10;
		vsota = vsota % 10;
		cout <<"stevilo bankovcev po 10 je "<<deset<<endl;
	}
	if (vsota > 5)
	{
		pet = vsota / 5;
		vsota = vsota % 5;
		cout <<"stevilo kovancev po 5 je "<<pet<<endl;
	}
	if (vsota > 1)
	{
		ena = vsota / 1;
		cout <<"stevilo kovancev po 1 je "<<ena<<endl;
	}

	do
	{
		cout <<"Ali zelite nadaljevati (D/N)"<<endl;
		cin >>odg;
	}
		while (odg != 'n' && odg !='d' && odg != 'N' && odg != 'D');
	}
	while (odg == 'D' || odg == 'd');

return 0;
}

   

gorNa vrh



Color_text.cpp:


#include <windows.h> // windows header file 
#include <stdio.h>      // C standard library i/o header 
#include <conio.h>     // needed for getch() 
#include <stdlib.h>    // C standard library

//setcolor 
//sets the default console color to 'color' 
void setcolor(unsigned short color) 
{ 
 HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE); 
 SetConsoleTextAttribute(hCon,color); 
} 

// main function 
int main(int argc, char *argv[]) 
{ 
 for(unsigned i = 0; i < 200; i++) 
 { 
  system("cls"); // clear the screen
  setcolor(i); // changes the color
  printf("color: %d\n", i); // prints the color ID 
  getchar(); // wait till a key is pressed
 } 
 return 0; 
} 

   

gorNa vrh



Delit2stevil.cpp:


//**********************************
// * PROGRAM ZA IZRACUN NAJVECJEGA  *
// * SKUPNEGA DELITELJA DVEH STEVIL *
// **********************************

#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
#include <windows.h>

void setcolor(unsigned short color) 
{ 
 HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE); 
 SetConsoleTextAttribute(hCon,color);
}

int deli(int a, int b)
{
int st;
st = a;
while (st > 1)
{
if (a % st == 0)
if (b % st == 0)
break;

st --;
}
return st;
}

main()
{
  char izbira;

  setcolor(14);
  int x, y, s;
  cout << "\n **********************************";
  cout << "\n * PROGRAM ZA IZRACUN NAJVECJEGA  *";
  cout << "\n * SKUPNEGA DELITELJA DVEH STEVIL *";
  cout << "\n **********************************";

  do
  {
  setcolor(11);
  cout << "\n\n\n Vstavi prvo stevilo >>> ";
  cin >> x;
  cout << "\n Vstavi drugo stevilo >>> ";
  cin >> y;
  setcolor(10);
  cout << "\n\n NAJVECJI skupni delitelj stevil " << x << " in " << y << " je stevilo  "<< deli (x, y);

	do
	{
        setcolor(14);
        cout << "\n\n\n Za ponoven izracun pritisni d ali D, za izhod iz programa n ali N >>> ";
        cin >> izbira;
     }
		while(izbira != 'n' && izbira !='N' && izbira != 'd' && izbira != 'D');
	}
	while (izbira == 'D' || izbira == 'd');


  //if(izbira == 'n' || izbira == 'N')
  system("cls");
  setcolor(4);
  cout << "\n\n\n\n\n\n\n\n\n\t ********* KONEC *********";
  setcolor(14);
  cout << "\n\n\n\n\n Pritisni tipko Enter za izhod iz programa >>> ";

  getchar();
  getchar();
  return 0;
}

    

gorNa vrh



Elipsa.cpp:


/*
   Ime programa: Elipsa, verzija 1.0
   Avtor: Bojan Dreu
   Opis: Program v C++, ki izracuna obseg in ploscino elipse.
         Podatke za polosi vtipkamo preko tipkovnice, podatke in rezultate pa
         izpise na zaslon.
         Program resi poljubno stevilo nalog, ki so tudi ostevilcene.
   Datum: September 2003
   Vse pravice pridrzane: Bojan Dreu, 2003
*/

#include<stdio.h>
#include<stdlib.h>

main()
{
 int stevec_nalog=1;
 double PI = 3.14159265359;
 float a, b;
 double o, pl;
 char odgovor;

 do
 {
  system("cls");
  printf(" ************************************************ ");
  printf("\n * PROGRAM ZA IZRACUN OBSEGA IN PLOSCINE ELIPSE * ");
  printf("\n *Avtor: Bojan Dreu, verzija 1.0, september 2003* ");
  printf("\n ************************************************ ");

  printf("\n\n\n Vnesi podatke za %d. elipso: ", stevec_nalog);

   do
   {
    printf("\n\n Velika polos a: ");
    scanf("%f",&a);
   }
   while(a <= 0);

    do
    {
     printf("\n Mala polos b: ");
     scanf("%f",&b);
    }
    while(b <=0);

  printf("\n\n REZULTATI %d. ELIPSE: ", stevec_nalog);
  printf("\n\n Velika polos a = %g ", a);
  printf("\n\n Mala polos b = %g ", b);

  o = PI * (a + b);

  pl = PI * a * b;

  printf("\n\n Obseg = %.5g ", o);
  printf("\n\n Ploscina = %.5g ", pl);

  stevec_nalog++;

	do
	{
      printf("\n\n\n Zelis izracunat se eno nalogo ( d ali D / n ali N ) ? >>> ");
      scanf("%s", &odgovor);
    }
   	while(odgovor != 'n' && odgovor !='N' && odgovor != 'd' && odgovor != 'D');

 }
 while (odgovor == 'd' || odgovor == 'D');

 system("cls");
 printf("\n\n\n\n\n\n\n\n\n\t ***** K O N E C ***** ");
 printf("\n\n\n\n Za izhod iz programa pritisni tipko [Enter] >>>>> ");

 getchar();
 getchar();
 return(0);
}

    

gorNa vrh



IZ3_SLO.cpp:


/* IZ3_SLO.cpp: Program za izracun obsega in povrsine trikotnika */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <conio.h>
#include <iostream.h>
#include <time.h>		//za uporabo casa
#include <windows.h>
#define SIZE 256		//dolocitev velikosti

void setcolor(unsigned short color) 
{ 
 HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE); 
 SetConsoleTextAttribute(hCon,color);
}


main()
{
FILE *vhod;
char vhodna[80];
float a, b, c;
float o, s, P;

setcolor(11);
  		putchar('\n');
  		printf("\t\t                         A\n");
		printf("\t\t                         *\n");
		printf("\t\t                        * *\n");
		printf("\t\t                       *   *\n");
		printf("\t\t                      *     *\n");
		printf("\t\t                     *       *\n");
		printf("\t\t                    *         *\n");
		printf("\t\t                   *           *\n");
		printf("\t\t                  *             *\n");
		printf("\t\t                 *               *\n");
  	  	printf("\t\t                *                 *\n");
		printf("\t\t               *  II  ZZZZZ  33333 *\n");
		printf("\t\t            b *   II     Z      3   * c\n");
		printf("\t\t             *    II   ZZZ       3   *\n");
		printf("\t\t            *     II   Z     3   3    *\n");
		printf("\t\t           *      II  ZZZZZ   333      *\n");
		printf("\t\t          *                             *\n");
		printf("\t\t         *                               *\n");
  	  	printf("\t\t        *                                 *\n");
		printf("\t\t       *                                   *\n");
		printf("\t\t      *                                     *\n");
		printf("\t\t     *                                       *\n");
		printf("\t\t    *                                         *\n");
		printf("\t\t   *                     a                     *\n");
		printf("\t\tC *********************************************** B ");
        setcolor(14);
        printf("[Enter]>>>");
	 	getchar();

    setcolor(10);
 	char buffer[SIZE];
	time_t curtime;
	struct tm *loctime;
	curtime = time (NULL);		//Uporabi trenuten as 
	loctime = localtime (&curtime);		//Spremeni ga v lokalno predstavitev.
	printf("\n\n\n\n\n\n\n\n\t\t\t        LEP POZDRAV !!!");		//Izpii ga v lepem formatu.

    strftime (buffer, SIZE, "\n\n\n\n\n\t\t Danes je  %d.%m.%Y, ura je %H in %M minut.\n", loctime);  // Prikazi ga v nasem formatu */
    fputs (buffer, stdout);


	printf("\n\n\n\n\n\n\t         ZELIM OBILO USPEHA pri uporabi programa IZ3 !  ");
    setcolor(14);
    printf("\n\n\n\n\t\t  Za nadaljevanje pritisni tipko [Enter] >>> ");
	getchar();
        {
    system("cls");
        setcolor(11);
		printf("\n\n\t\t=======================================================\n");
		printf("\t\t|                   ***** IZ3 *****                   |\n");
		printf("\t\t|  PROGRAM ZA IZRACUN OBSEGA IN POVRSINE TRIKOTNIKA   |\n");
		printf("\t\t|              Verzija 1.2, februar 2003              |\n");
		printf("\t\t|                                                     |\n");
		printf("\t\t| Avtor: Bojan Dreu, Leskovec 12, 2331 Pragersko, SLO |\n");
                		printf("\t\t|               E-mail:  dr.eu@email.si               |\n");
		printf("\t\t=======================================================\n\n\n\n");
		printf("\t\tPROGRAM IZ PODATKOV NA POLJUBNI VHODNI DATOTEKI IZRACUNA:\n\n\n");
		printf("\t\t\t       -  O B S E G  TRIKOTNIKA\n\n");
		printf("\t\t\t\t\t   in\n\n");
		printf("\t\t\t    -  P O V R S I N O  TRIKOTNIKA\n\n");
		printf("\t\t--------------------------------------------------------- ");
        setcolor(14);
        printf("\n\t\t\t Za nadaljevanje pritisni tipko [Enter] >>> ");
    getchar();
    }
    {
     system("cls");
                     setcolor(14);
                     cout << "\n\n Podatki na vhodni datoteki, ki mora biti formata txt, ";
                     cout << "\n morajo biti zapisani v naslednji obliki: a b c";
                     cout << "\n\n\t na primer: 6.592 7.008 2.375  ";
                     cout << "\n\t       ali: 3. 9 5. ";
                     cout << "\n\t       ali: 2 8.3 6 ";
                     cout << "\n\n V vhodni datoteki ne sme biti crk !!!";


        cout << "\n\n\n Vtipkaj ime in tip datoteke s podatki ter celotno pot do nje :\n\n";
        cout << " vnos >>> ";
        cin>>vhodna; //Preberi ime vhodne datoteke in podatke iz nje
       }
  vhod= fopen(vhodna,"r");

                     if(vhod == NULL)                             // neuspesno odpiranje vhodne datoteke
                     {
                      system("cls");
                      setcolor(4);
                      cout << "\a\n\n\n\n\n\n\n Vtipkal si ime datoteke s podatki >>>  " << vhodna << "  . \n";
                      cout << "\n\n\n\n\n NE MOREM ODPRETI TE VHODNE DATOTEKE, KER NE OBSTOJA !!! ";  //Opozorilo
                      cout << "\n\n\n\n\n\n\n\t ********** KONEC PROGRAMA ********** ";
                      setcolor(14);
                      cout << "\n\n\n\n\n\t Za izhod pritisni tipko [Enter] >>> ";
                      getchar();
                      exit(0);
                     }


  int stevec_trikotnikov=0;
  int stevec=0;
   int count;

   while ((count = fscanf(vhod, "%f %f %f",&a, &b, &c)) != EOF)
   {

    if(count < 3)
    {
      stevec++;
      char bad;
      fscanf(vhod, "%c", &bad);
      setcolor(4);
      printf("\n Podatki v  %d. vrstici datoteke so napacni",stevec);
      printf("\n Napaka v podatkih: crka %c\n", bad);
      getchar();
    }
    else
     {

     o= a + b + c;
     s= (a + b + c) / 2.0;
     P = sqrt(s * ((s - a) * (s - b) * (s - c)));	   	//Izracun povrsine trikotnika


    stevec_trikotnikov++;
    system("cls");
    setcolor(10);
    printf("\n\n PODATKI STRANIC %d. TRIKOTNIKA:\n", stevec_trikotnikov);
    printf(" -------------------------------------------------------\n\n");
    printf(" Stranica  a = %5.3f m\n", a);
    printf(" Stranica  b = %5.3f m\n", b);
    printf(" Stranica  c = %5.3f m\n", c);
    printf(" -------------------------------------------------------\n");

    setcolor(4);
	if(a < 0 )
		{
		printf(" Napacni podatki stranice a ! Stranica a je negativna !\n");
 		}

	if(a == 0 )
		{
		printf(" Napacni podatki stranice a ! Stranica a je enaka 0 !\n");
 		}

	//if(a != '0' && a != '1' && a != '2' && a != '3' && a != '4' && a != '5' && a != '6' && a != '7'&& a != '8'  && a != '9' )
		//{
		//printf(" Napacni podatki stranice a ! Stranica a je crka %c !\n");
 		//}

           if(b < 0 )
           {
		         printf(" Napacni podatki stranice b ! Stranica b je negativna !\n");

           }

           if(b == 0 )
           {
		         printf(" Napacni podatki stranice b ! Stranica b je enaka 0 !\n");

           }

	                   if(c < 0 )
                         {
		                       printf(" Napacni podatki stranice c ! Stranica c je negativna !\n");
                         }

	                   if(c ==0 )
                         {
		                       printf(" Napacni podatki stranice c ! Stranica c je enaka 0 !\n");
                         }

        setcolor(11);
		printf("\n\n REZULTATI:\n");
		printf(" -------------------------------------------------------\n");
 		   setcolor(4);
           if(  a <= 0 || b <= 0 || c <= 0)
           {
		         printf("\n OBSEG %d. trikotnika NI MOZNO IZRACUNATI !!!", stevec_trikotnikov);

           }
	           if(s <= a || s <= b || s<= c)
	           {
	            printf("\n POVRSINO %d. trikotnika NI MOZNO IZRACUNATI !!!\n",  stevec_trikotnikov);
                setcolor(11);
                printf(" =======================================================\n");
                setcolor(14);
	            printf(" Za naslednji trikotnik pritisni tipko Enter --> ");
	            getchar();

                }
            else
            {
             setcolor(11);
             printf("\n OBSEG %d. trikotnika je:   %5.3f m.\n\n",  stevec_trikotnikov, o);
             printf(" POVRSINA %d. trikotnika je:   %5.3f m2.\n",  stevec_trikotnikov, P);
             printf(" =======================================================\n");
             setcolor(14);
             printf(" Za naslednji trikotnik pritisni Enter -->");
             getchar ();
            }
        }
    }
    setcolor(4);
	printf("\n\n\n\n\n\n\n\n\n\n\t\t *** PODATKOV NA DATOTEKI JE ZMANJKALO !! ***\n\n\n\n\n\n");
	
    fclose(vhod);
    cout << "\n\n\n\n\n\n\n\n\n\n" << "\t\t     ********** KONEC PROGRAMA ********** ";
    setcolor(14);
    cout << "\n\n\n\t\t     Za izhod pritisni tipko [Enter] >>> ";

getchar();
return 0;
}

    

gorNa vrh



TicTacToe.cpp (Križci in krožci):


//Tic Tac Toe
//Krizci in krozci
//Prevedel Bojan Dreu

#include <iostream.h> 
#include <stdlib.h> 
#include <conio.h> 

char matrix[3][3];//={0}; 
void cou(void); 
int main() 
{ 
int m,n; 
char ch='y'; 
while(ch=='Y'||ch=='y'){ 
for (m=0;m<3;m++)for (n=0;n<3;n++)matrix[m][n]= '\0'; 
int i,j,sum=0; 
while ( sum < 10){ 
if (sum == 0) cou(); 
cout<<"\nIgralec 1 ima 'X': izberi vrstico in stolpec"<<endl;
cout<<"Vrstica : ";
cin>>i;
cout<<"Stolpec : ";
cin>>j;
for (;i>3 || i<1 || j>3 || j<1 ||('X'==matrix[i-1][j-1]||'O'==matrix[i-1][j-1]);)
{
cout<<"\nOprosti fant, toda moral bos izbrati drugo pozicijo.\n";
cout<<"Vrstica : ";cin>>i;
cout<<"Stolpec : ";cin>>j;
}

matrix[i-1][j-1]='X'; 
sum++; 
cou(); 
//Preveri zmago 
if (matrix[0][0]=='X' && matrix[0][0]==matrix[1][1] && matrix[1][1]==matrix[2][2]) {cout<<"\nIgralec 1 je zmagal !"<<endl;break;}
if (matrix[2][0]=='X' && matrix[2][0]==matrix[1][1] && matrix[1][1]==matrix[0][2]) {cout<<"\nIgralec 1 je zmagal !"<<endl;break;}
if (matrix[0][0]=='X' && matrix[0][0]==matrix[1][0] && matrix[1][0]==matrix[2][0]) {cout<<"\nIgralec 1 je zmagal !"<<endl;break;}
if (matrix[0][1]=='X' && matrix[0][1]==matrix[1][1] && matrix[1][1]==matrix[2][1]) {cout<<"\nIgralec 1 je zmagal !"<<endl;break;}
if (matrix[0][2]=='X' && matrix[0][2]==matrix[1][2] && matrix[1][2]==matrix[2][2]) {cout<<"\nIgralec 1 je zmagal !"<<endl;break;}
if (matrix[0][0]=='X' && matrix[0][0]==matrix[0][1] && matrix[0][1]==matrix[0][2]) {cout<<"\nIgralec 1 je zmagal !"<<endl;break;}
if (matrix[1][0]=='X' && matrix[1][0]==matrix[1][1] && matrix[1][1]==matrix[1][2]) {cout<<"\nIgralec 1 je zmagal !"<<endl;break;}
if (matrix[2][0]=='X' && matrix[2][0]==matrix[2][1] && matrix[2][1]==matrix[2][2]) {cout<<"\nIgralec 1 je zmagal !"<<endl;break;}

if (sum == 9)
{
cout<<"\nIgre je konec in nobeden ni zmagal, ha, ha, ha, oba smrdita !!!"<<endl; break;
} //sum=9 ker je samo 9 monih pozicij v igri

//Na vrsti je drugi igralec
cout<<"\nIgralec 2 ima 'O': izberi vrstico in stolpec"<<endl;

cout<<"Vrstica : ";
cin>>i; 
cout<<"Stolpec : ";
cin>>j; 

for (;i>3 || i<1 || j>3 || j<1 ||('X'==matrix[i-1][j-1]||'O'==matrix[i-1][j-1]);)
{
cout<<"Oprosti fant, toda moral bos izbrati drugo pozicijo.\n";
cout<<"Vrstica : ";
cin>>i;
cout<<"Stolpec : ";
cin>>j;}
matrix[i-1][j-1]='O';
sum++; 
 
//Igralna ploskev
cou(); 
//Preveri zmago 
if (matrix[0][0]=='O' && matrix[0][0]==matrix[1][1] && matrix[1][1]==matrix[2][2]) {cout<<"Igralec 2 je zmagal !"<<endl;break;}
if (matrix[2][0]=='O' && matrix[2][0]==matrix[1][1] && matrix[1][1]==matrix[0][2]) {cout<<"Igralec 2 je zmagal !"<<endl;break;}
if (matrix[0][0]=='O' && matrix[0][0]==matrix[1][0] && matrix[1][0]==matrix[2][0]) {cout<<"Igralec 2 je zmagal !"<<endl;break;}
if (matrix[0][1]=='O' && matrix[0][1]==matrix[1][1] && matrix[1][1]==matrix[2][1]) {cout<<"Igralec 2 je zmagal !"<<endl;break;}
if (matrix[0][2]=='O' && matrix[0][2]==matrix[1][2] && matrix[1][2]==matrix[2][2]) {cout<<"Igralec 2 je zmagal !"<<endl;break;}
if (matrix[0][0]=='O' && matrix[0][0]==matrix[0][1] && matrix[0][1]==matrix[0][2]) {cout<<"Igralec 2 je zmagal !"<<endl;break;}
if (matrix[1][0]=='O' && matrix[1][0]==matrix[1][1] && matrix[1][1]==matrix[1][2]) {cout<<"Igralec 2 je zmagal !"<<endl;break;}
if (matrix[2][0]=='O' && matrix[2][0]==matrix[2][1] && matrix[2][1]==matrix[2][2]) {cout<<"Igralec 2 je zmagal !"<<endl;break;}
}

cout<<"\n\n\nBi rada igrala se enkrat ??? (Y - N) ";

cin>>ch; 
} 
//      system("PAUSE");   //odstranil
      return 0; 
} 


void cou(void) 
{ 
//Igralna ploskev 
system("cls"); //dodal
cout<<"\n\t\t       ************************ "; //dodal
cout<<"\n\t\t       *   KRIZCI IN KROZCI   *"; //dodal
cout<<"\n\t\t       * Prevedel: Bojan Dreu *"; //dodal
cout<<"\n\t\t       ************************\n\n\n\n"; //dodal

cout<<"\t\t                1   2   3\n"<<endl;
cout<<"\t\t             1  "<<matrix[0][0]<<" | "<<matrix[0][1]<<" | "<<matrix[0][2]<<endl; 
cout<<"\t\t               ---|---|---\n"; 
cout<<"\t\t             2  "<<matrix[1][0]<<" | "<<matrix[1][1]<<" | "<<matrix[1][2]<<endl; 
cout<<"\t\t               ---|---|---\n"; 
cout<<"\t\t             3  "<<matrix[2][0]<<" | "<<matrix[2][1]<<" | "<<matrix[2][2]<<"\n\n\n"; 
} 

    

gorNa vrh



Poraba_goriva.cpp:


/*
Poraba_v3.exe - Poraba_goriva.cpp, verzija 3.0, januar 2007 - IZRACUN PORABE GORIVA

Program izracuna porabo goriva avtomobila.
Podatke (datum tocenja, prevozene kilometre, natocene litre goriva, ceno goriva) in 
rezultate (znesek placila, porabo goriva na 100 km) nam izpise na zaslon in 
v poljubno imenovano izhodno datoteke tipa TXT.

Avtor:      Bojan Dreu
Naslov:     Leskovec 12 a, 2331 Pragersko, SLO
E-mail:     my.3home.email@gmail.com
Internet:   http://cpp-beginner.50webs.com
Datum:      06.01.2007
*/


#include <iostream>
#include <stdio.h>
#include <windows.h>

using namespace std;


/* Funkcija Barva_pisave() - funkcija za dolocitev barve izpisanega teksta na zaslonu */
void Barva_pisave(unsigned short color)
{ 
 HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE); 
 SetConsoleTextAttribute(hCon,color);
}

/* Funkcija Meni() - funkcija za izpis izbirnega menija */
void Meni()
{
 Barva_pisave(10);  //barva teksta
 cout << "\n\n\n\t IZBIRNI MENI: \n\n";  //izpis izbirnega menija za podatke
 cout << "\t 0 - IZHOD iz programa \n";
 cout << "\t 1 - POMOC \n";
 cout << "\t 2 - IZRACUN porabe goriva \n";
 cout << "\t ======================================================= \n";
 Barva_pisave(14);  //barva teksta
 cout << "\t Vpisi stevilko izbire in pritisni tipko [Enter] >>> ";
}

/* Funkcija Opozorilo() - funkcija za izpis opozorila na zaslon pri napacni izbiri iz menija */
void Opozorilo()
{
 system("cls");  //brisanje zaslona
 Barva_pisave(4);  //barva teksta
 cout << "\a\n\n\t\t                  * * * * * * * \n";  //izpis opozorila ob napacni izbiri iz menija
 cout << "\t\t                *               * \n";
 cout << "\t\t              *                   * \n";
 cout << "\t\t            *                       * \n";
 cout << "\t\t          *                           * \n";
 cout << "\t\t          *   O P O Z O R I L O !!!   * \n";
 cout << "\t\t          *                           * \n";
 cout << "\t\t          * Taksna izbira ni mozna !! * \n";
 cout << "\t\t          *                           * \n";
 cout << "\t\t          *     Poskusi ponovno !     * \n";
 cout << "\t\t          *                           * \n";
 cout << "\t\t            *                       * \n";
 cout << "\t\t              *                   * \n";
 cout << "\t\t                *               * \n";
 cout << "\t\t                  * * * * * * * \n";
}

/* Funkcija Pomoc() - funkcija za izpis pomoci pri programu */
void Pomoc()
{
 system("cls");  //brisanje zaslona
 Barva_pisave(12);  //barva teksta
 cout << " **************************************************************** \n";  //izpis pomoci za program
 cout << " *                        P  O  M  O  C                         * \n";
 cout << " *      za program Poraba_v3.exe, verzija 3.0, januar 2007      * \n";
 cout << " **************************************************************** \n\n\n";
 Barva_pisave(3);  //barva teksta
 cout << " Program nam izracuna porabo goriva avtomobila.\n";
 cout << " Vnesemo datum, ko smo natocili gorivo, \n"; 
 cout << " koliko kilometrov smo prevozili, \n";
 cout << " koliko goriva smo natocili \n";
 cout << " in ceno za liter goriva. \n\n";
 cout << " Nato nam program izracuna: \n\n";
 cout << " - skupni znesek za placilo goriva. \n";
 cout << " - porabo goriva na 100 kilometrov. \n\n";
 cout << " Program nam nato izpise vse vhodne podatke in rezultate \n";
 cout << " na zaslon in v poljubno imenovano izhodno datoteko tipa TXT. \n\n";
 cout << " Ce datoteka ze obstoja, podatke in rezultat zapise na konec \n";
 cout << " te datoteke, drugace pa ustvari novo. \n";

 Barva_pisave(14);  //barva teksta
 cout << "\n\n Za nadaljevanje pritisni tipko [Enter] >>> ";
 cin.ignore();
 cin.ignore();

 system("cls");  //brisanje zaslona
 Barva_pisave(12);  //barva teksta
 cout << "\n VNOS PODATKOV: ";
 Barva_pisave(3);  //barva teksta
 cout << "\n\n\n Pri vnosu decimalnih stevil moramo uporabljati decimalno piko. ";
 cout << "\n\n Datum, ko smo natocili gorivo, ";
 cout << "\n vtipkamo na primer: 02.01.2007 ";
 cout << "\n\n Stevilo prevozenih kilometrov, ";
 cout << "\n vtipkamo na primer: 523.8 ali 489. ali 601 ";
 cout << "\n\n Stevilo natocenih litrov goriva, ";
 cout << "\n vtipkamo na primer: 23.8 ali 48. ali 51 ";
 cout << "\n\n Cena za liter goriva, ";
 cout << "\n vtipkamo na primer: 0.98 ali 1. ali 1 ";

 Barva_pisave(4);  //barva teksta
 cout << "\n\n\n\n\t VTIPKANI PODATKI NE SMEJO BITI CRKE !!! ";
 Barva_pisave(14);  //barva teksta
 cout << "\n\n\n\n Za nadaljevanje pritisni tipko [Enter] >>> ";
 cin.ignore();

 system("cls");  //brisanje zaslona
 Barva_pisave(12);  //barva teksta
 cout << "\n NAPAKE, OPOZORILA ";
 Barva_pisave(3);  //barva teksta
 cout << "\n\n\n Program nam izpise vse vhodne podatke in rezultate ";
 cout << "\n v poljubno imenovano izhodno datoteko tipa TXT. ";
 cout << "\n\n\n Ce ne navedemo prave obstojece poti za izhodno datoteko, ";
 cout << "\n nam program po zvocnem signalu javi, da te datoteke ne more ustvariti. ";
 cout << "\n\n Ce za izhodno datoteko ne navedemo poti in tipa datoteke, jo bo ";
 cout << "\n program brez tipa datoteke shranil tja, kjer se nahaja program Poraba.exe. ";
 cout << "\n\n To izhodno datoteko lahko kasneje spremenimo v TXT tip datoteke ";
 cout << "\n in tako lahko pridemo do zapisanih podatkov in rezultatov. ";
 Barva_pisave(14);  //barva teksta
 cout << "\n\n\n\n\n\n\n\n\n Za nadaljevanje pritisni tipko [Enter] >>> ";
 cin.ignore();

 system("cls");  //brisanje zaslona
 Barva_pisave(12);  //barva teksta
 cout << "\n IZPIS PODATKOV IN REZULTATOV ";
 Barva_pisave(3);  //barva teksta
 cout << "\n\n\n Podatke in rezultate program izpise na zaslon ";
 cout << "\n in v poljubno izhodno datoteko tipa TXT ";
 cout << "\n v naslednji obliki: ";
 cout << "\n\n Datum : 02.01.2007 ";
 cout << "\n\n Stevilo prevozenih km : 523.8 ";
 cout << "\n\n Stevilo natocenih litrov goriva : 48.3 ";
 cout << "\n\n Cena za liter goriva : 0.98 EUR";
 cout << "\n\n\n Za placilo: 47.334 EUR";
 cout << "\n\n\n PORABA GORIVA NA 100 KM JE : 9.22 L";
 cout << "\n\n *********************************************** ";
 Barva_pisave(14);  //barva teksta
 cout << "\n\n Za izhod iz pomoci pritisni tipko [Enter] >>> ";
}

/* Glavna funkcija() */
int main ()
{
 char izbor;
 char datum[11];
 float kilometri, litri, cena;
 double znesek;
 double poraba;

 Barva_pisave(11);
 cout << "\n\n\n\t *******************************************************";
 cout << "\n\t *              P  O  R  A  B  A  _  v  3              *";
 cout << "\n\t *     PROGRAM ZA IZRACUN PORABE GORIVA AVTOMOBILA     *";
 cout << "\n\t *               Verzija 3.0, januar 2007              *";
 cout << "\n\t * Avtor: Bojan Dreu, Leskovec 12, 2331 Pragersko, SLO *";
 cout << "\n\t *               E-mail: dr.eu@email.si                *";
 cout << "\n\t *         http://cpp-beginner.freehost386.com         *";
 cout << "\n\t *******************************************************";

 Meni();
 cin >> izbor;  //preberi vtipkani izbor za meni

 while(izbor != '0')  //dokler je vtipkan znak razlicen od 0
 {
   switch(izbor)  //vklopi izbiro
   {
     case'1':  //v primeru vtipkanega znaka 1 (Pomoc)
     {
       Pomoc();//izpis pomoči za program
       cin.ignore();
       system("cls");  //brisanje zaslona
       break;
     }

       case'2':  //v primeru vtipkanega znaka 2 (izracun porabe)
       {
         system("cls");
         Barva_pisave(3);
	     cout <<"\n Datum : ";
	     cin >>datum;

	     cout <<"\n\n Stevilo prevozenih km : ";
	     cin >>kilometri;

	     cout <<"\n\n Stevilo natocenih litrov goriva : ";
	     cin >>litri;

	     cout <<"\n\n Cena za liter goriva EUR : ";
	     cin >>cena;

         znesek = cena * litri;

         Barva_pisave(10);
	     cout <<"\n\n\n Za placilo :  " << znesek << " EUR ";

	     poraba = (litri * 100) / kilometri;

         Barva_pisave(10);
	     printf("\n\n\n PORABA GORIVA NA 100 KM JE  %.2f L", poraba);

         Barva_pisave(8);
         printf("\n\n ***************************************************************** ");
                  
           FILE *izhod;
           char izhodna[80];

           do  
           {
           Barva_pisave(14);
           cout << "\n\n\n Vtipkaj ime in tip izhodne datoteke (txt) ter celotno pot do nje: \n\n";
           cout << " vnos >>> ";
           cin >> izhodna;

           izhod = fopen(izhodna, "a");// odpiranje izhodne datoteke in dodajanje, ce ze obstaja

             system("cls");
             Barva_pisave(6);
             cout << "\a\n\n\n\n\n\n\n Vtipkal si ime datoteke za zapis rezultatov >>>  " << izhodna << " !!! \n";
             Barva_pisave(4);
             cout << "\n\n\n\n\n\t PODANE IZHODNE DATOTEKE NE MOREM USTVARITI !!! ";//izpise napako
           }while(izhod == NULL); // neuspesno odpiranje izhodne datoteke

	       fprintf(izhod, "\n Datum : %s", datum);
	       fprintf(izhod, "\n\n Stevilo prevozenih km : %.2f", kilometri);
	       fprintf(izhod, "\n\n Stevilo natocenih litrov goriva : %.2f", litri) ;
	       fprintf(izhod, "\n\n Cena za liter goriva : %.2f EUR", cena);
	       fprintf(izhod, "\n\n\n Za plailo: %.2f EUR", znesek);
	       fprintf(izhod, "\n\n\n PORABA GORIVA NA 100 KM JE : %.2f L", poraba);
           fprintf(izhod, "\n\n ****************************************************\n\n\n");

           fclose(izhod);
                 
           system ("cls");
           Barva_pisave(4);
           cout << "\n\n\n\n\n\n\n\n\n\n\n\t\t ********** KONEC PROGRAMA ********** \n\n\n\n\n\n\n\n";
           Barva_pisave(14);
           cout << "\t\t Za izhod iz programa pritisni tipko [Enter] >>> ";
           cin.ignore();
           cin.ignore();
	       return 0;  //izhod iz programa
       }

         default:  //v primeru izbire drugacnega znaka od 0, 1, 2 ali 3
         {
           Opozorilo();  //izpis opozorila ob napacni izbiri
           break;
         }
   }       
           
   Barva_pisave(10);  //barva teksta
   Meni();  //izpie meni
   cin >> izbor;  //preberi izbiro za meni
 }   

 system("cls");  //brisanje zaslona
 Barva_pisave(4);  //barva teksta
 cout << "\n\n\n\n\n\n\n\n\n\n\t\t  ********** KONEC PROGRAMA ********** ";  //obvestilo o koncu programa

 Barva_pisave(14);  //barva teksta
 cout << "\n\n\n\n\n\n\n\t\t  Za izhod iz programa pritisni tipko [Enter] >>> ";
 cin.ignore();
 cin.ignore();
 return(0);  //izhod iz programa
}

    

gorNa vrh



SIT2EVRE.cpp:


/*
   Ime programa: SIT2EUR.exe, verzija 1.0
   Avtor: Bojan Dreu
   Opis: Program v C++, ki preracuna SIT v EURE in obratno
         Znesek vtipkamo preko tipkovnice, podatke in rezultate pa
         izpise na zaslon.
   Datum: Maj 2006
   Vse pravice pridrzane: Bojan Dreu, 2006
*/

#include<stdio.h>
#include<stdlib.h>

main()
{
 int izbira;
 float SIT, EUR;
 char odgovor;

 do
 {
  system("cls");
  printf("\n **********************************************");
  printf("\n * PROGRAM ZA PRERACUN SIT v EUR (in obratno) *");
  printf("\n *           Avtor: Bojan Dreu, SLO           *");
  printf("\n *           Verzija 1.0,  maj 2006           *");
  printf("\n **********************************************");

  printf("\n\n\n\n\n\n\n Ce zelis preracunati tolarje v eure pritisni 1, ");
  printf("\n\n\n ce pa zelis preracunati eure v tolarje, pritisni 2. ");
  printf("\n\n\n\n\n\n\n Vtipkaj izbrani preracun >>> ");
  scanf("%d", & izbira);

   switch (izbira)
   {
    case 1:
      system("cls");
      printf("\n\n\n\n Vpisi znesek tolarjev: ");
      scanf("%f", & SIT);
      EUR = SIT / 239.64;//bilo je 226.87;
      printf("\n\n\n\n\n %.2f tolarjev je %.2f eurov. ", SIT, EUR);
      break;

    case 2:
      system("cls");
      printf("\n\n\n\n\n Vpisi znesek eurov: ");
      scanf("%f", & EUR);
      SIT = EUR * 239.64;//bilo je 226.87;
      printf("\n\n\n\n\n %.2f eurov je %.2f tolarjev. ", EUR, SIT);
      break;

    default:
      system("cls");
      printf("\n\n\n\n\n Vpisal si NAPACNO IZBIRO !!!\n");
   }

   do
   {
    printf("\n\n\n\n\n\n\n\n\n Zelis opraviti se en preracun?");
    printf("\n\n ( d ali D  za DA,  n ali N za NE)   >>> ");
    scanf("%s", &odgovor);
   }
   while(odgovor != 'n' && odgovor !='N' && odgovor != 'd' && odgovor != 'D');

 }
 while (odgovor == 'd' || odgovor == 'D');

 system("cls");
 printf("\n\n\n\n\n\n\n\n\n ********* K O N E C ********* ");
 printf("\n\n\n\n\n\n\n\n\n Za izhod iz programa pritisni tipko [Enter] >>>>> ");

 getchar();
 getchar();
 return (0);
}

    

gorNa vrh



sieve.cpp - Sito za praštevila:


#include <stdio.h>
#include <malloc.h>
#include <time.h>

#define TEST(f,x)	(*(f+(x)/16)&(1<<(((x)%16L)/2)))
#define SET(f,x)	*(f+(x)/16)|=1<<(((x)%16L)/2)

int
main(int argc, char *argv[])
{
  unsigned char *feld=NULL, *zzz;
  unsigned long teste=1, max, mom, hits=1, count, alloc, s=0, e=1;
  time_t begin;

  if (argc > 1)
    max = atol (argv[1]) + 10000;
  else
    max = 14010000L;

  while (feld==NULL)
        zzz = feld = malloc (alloc=(((max-=10000L)>>4)+1L));

  for (count=0; count<alloc; count++) *zzz++ = 0x00;

  printf ("Searching prime numbers to : %ld\n", max);

  begin = time (NULL);
  while ((teste+=2) < max)
        if (!TEST(feld, teste)) {
                if  (++hits%2000L==0) {printf (" %ld. prime number\x0d", hits); fflush(stdout);}
                for (mom=3L*teste; mom<max; mom+=teste<<1) SET (feld, mom);
                }

  printf (" %ld prime numbers foundn %ld secs.\n\nShow prime numbers", 
          hits, time(NULL)-begin);

  while (s<e) {
        printf ("\n\nStart of Area : "); fflush (stdout); scanf ("%ld", &s);
        printf ("End   of Area : ");     fflush (stdout); scanf ("%ld", &e);

        count=s-2; if (s%2==0) count++;
        while ((count+=2)<e) if (!TEST(feld,count)) printf ("%ld\t", count);
        }
  free (feld);
  return 0;
}

    

gorNa vrh



board1.cpp - štiri v vrsto:


// Author: Inder Mohan Singh
// Project Name:  Simple Board  Game  (oop concept)
// Number of Files: 3
// Files Name: Board.cpp, game.cpp, board.h

/* Code provided by Author Inder Mohan Singh (http://www.geocities.com/imsb69) 'as is', 
   without warranties as to performance, fitness, <br>merchantability,and any other warranty
   (whether expressed or implied ).Terms of Agreement: By using this source code, you agree 
   to the following terms...
     1) You may use this source code in personal projects and may compile it into an 
	    .exe/.dll/.ocx and distribute it in binary format freely and with no charge.
     2) You MAY NOT redistribute this source code (for example to a web site) without 
	    written permission from the original author.Failure to do so is a violation of copyright
	    laws.
     3) You may link to this code from another website, provided it is not wrapped in a frame.

	If you find any bug in this source codes please e-mail imsb69@yahoo.com
	
 */

#include <iostream.h>
#include <conio.h>
#include "board1.h"
#include <stdio.h>  //dodal

void main(void)
{
    Game game;
	game.play();
	getchar();

}

    


board1.h:


// define the  different class for simple board game

 const int MAX_ROWS = 9;		// Maximum rows
 const int MAX_COLUMNS = 9;	// Maximum columns

 const int WINNING_LINE = 4;
 const int NUM_PLAYERS = 2;    	// Maximum numbers of players is 4
 const int DEFAULT_ROWS = 6;		// Default numbers of rows
 const int DEFAULT_COLUMNS = 7;  // Default numbers of columns

 enum Boolean {False , True };
 enum BoardState {DRAW, WIN, PLAY};

 const char INVISIBLE = ' ';
 const int SELECT_REPRESENTATION = 1;



// Used to represent a counter that will be dropped into column on the gaming
// board

class Counter
{
	 private:
	 static int tokenNum;	// which token to allocate
	 char theToken;			// the token used as the counter

	 public:
	 static void setTokenNum();
	 Counter();
	 Counter( const char);
	 Counter (const int);
	 ~Counter() {}
	 char token() const;       // returns the characters
	 void display () const;    // display the character to screen
};



// represent a game player, makes move and announces win or draw

class Player
{
    private:
	 Counter thePlayersCounter;

	 public:
	 Player ();          // constructor assigns a token for the player
	 ~Player() { }       // destructor
	 int getMove(const Boolean ) const;      // Ask for a move

	 Counter getCounter () const;         // Get a counter

	 void announce(const BoardState)const;  // allows the player to announce the win or draw


};

// represent the individual cell in the gaming board

class Cell
{
    private:
	 Counter theCounter;		// the counter in this cell
	 public:
	 Cell();     // sets the cel to contain the space ' ' character
	 ~Cell() {}  // destructor
	 void clear();   // clear the cell to place space character ' '.
	 void drop (const Counter);     // drops the counter in the cell
	 char holds()const;   // report back the token representation of the counter
	 void display()const; // request the counter to display itself


};


//The gaming board which which appears on the computer
class Board
{
	private:
	Cell grid[MAX_ROWS][MAX_COLUMNS];	//playing board made up of cells
	int height[MAX_COLUMNS];				// current height of counters col
	int rowSize;
	int columnSize;							// size of the playing area
	int lastRow;        // row of the last counter
	int lastCol;        // col of the last counter
	int numEmptyCells;    // remaining empty cell

	protected:
	int checkForWin ( const int ,const int ,const int, const char )const;
	void addCounterToBoard (const int,const Counter);
	Boolean isThereAWin()const ;  // check for a win

	 public:
					  // constructor default size 6 x 7
	 Board (const int rows =DEFAULT_ROWS,const int columns = DEFAULT_COLUMNS);

	 ~Board() { }      // destructor
	  // reset the game for new game
	 void reset (const int rows =DEFAULT_ROWS,const int columns = DEFAULT_COLUMNS);

	 void dropInColumn (const int,const Counter );      // drop the counter in the column

	 Boolean moveOkForColumn (const int) const;         // check for valid col number and
														 // col is not full

	 void display()const;                    // draw the board

	 BoardState situation()const;                   // reports the state of the game


};


// Co-ordinate Board Game

class Game
{
	 private:                     // the playing board
	 Board board;
	 BoardState state;
	 Player contestant[NUM_PLAYERS];    // holds the number of player
	 int num;

	 public:
	 Game();
	 ~Game(){}  // destructor
	 void play ();       // controls the game play until the state of the game
								// changes

};

// end of board.h

    


game.cpp:


// definition of members method of all the classes

#include <iostream.h>
#include <conio.h>
#include <stdio.h> //dodal
#include <stdlib.h> //dodal

#include "board1.h"


int Counter::tokenNum ;		// allocate storage to the static

// sets the representational token to invisible
void Counter:: setTokenNum()
{
	tokenNum = 0;

}

// sets the representational token to the one requested
inline Counter::Counter()
{
	theToken = INVISIBLE;
}

// dummy parameter to distinguish constructor
Counter::Counter(const int)
{  // Subscripting operator used to deliver a token to use asa counter
	theToken = "XO$#"[tokenNum++];

}

Counter::Counter(const char representation)
{
	theToken = representation;
}

inline char Counter::token() const
{
	return theToken;
}

inline void Counter::display() const
{
	cout << theToken;
}

// assigns the token for the player
Player::Player()
{
	thePlayersCounter = Counter (SELECT_REPRESENTATION);
}

int Player::getMove(const Boolean first) const
{
	int move;
	if (first != True)
		cout << "\nNAPAKA -- Napacna izbira " << endl;
	cout << "\nPoteza za igralca  " << thePlayersCounter.token() << "  je ";
		cin >> move;
	return move -1;
}

inline Counter Player::getCounter() const
{
	return thePlayersCounter;
}



void Player::announce(const BoardState what) const
{
	cout << "\n\n\nIgralec  " << thePlayersCounter.token();
	switch (what)
	{
		case WIN : cout << "  je ZMAGAL !" << endl;
						break;
		case DRAW : cout << "  - konec igre - plosca je polna !" << endl;
						break;
	}
cout << "\n\nPritisni tipko [Enter] za izhod >>> "; //dodal
}


Cell::Cell()
{
	theCounter = Counter(INVISIBLE);
}

inline void Cell:: clear()
{
	theCounter = Counter(INVISIBLE);
}

inline void Cell:: drop(const Counter c)
{
	theCounter = c;
}

inline char Cell::holds() const
{
	return theCounter.token();
}

inline void Cell::display() const
{
	theCounter.display();
}



Board::Board (const int rows,const int columns)
{
	 reset(rows, columns);
}
void Board::reset(const int rows,const int columns)
{
	rowSize= rows;
	columnSize= columns;

	for (int i = 0; i < columnSize; i++)
	{
		for (int j =0; j < rowSize; j++)
			grid[j][i].clear();
		height[i] = 0;
	}
	lastRow=lastCol = 0;
	numEmptyCells = rows*columns;
}

void Board::dropInColumn (const int column, const Counter c)
{
	lastCol = column;
	lastRow=height[column];
	addCounterToBoard(column, c);
}

Boolean Board::moveOkForColumn (const int column) const
{
	if (column >= 0 && column < columnSize)
		if (height[column] < rowSize)
			return True;
	return False;
}

void Board:: addCounterToBoard(const int column, const Counter playersCounter)
{
	grid[height[column]] [column].drop(playersCounter);
	height[column]++;
	numEmptyCells--;
}

BoardState Board::situation() const
{
	if (isThereAWin() == True)
		return WIN;
	if (numEmptyCells == 0)
		return DRAW;
	return PLAY;
}

Boolean Board::isThereAWin() const
{
	char counter = grid[lastRow][lastCol].holds();
	for (int direction = 1; direction <=4; direction++)
	{
		int countersInaLine = checkForWin(direction, lastRow, lastCol, counter)
				+  checkForWin(direction + 4, lastRow, lastCol, counter) - 1;
		if(countersInaLine >= WINNING_LINE)
			return True;
	}
	return False;
}

int Board:: checkForWin(const int direction, const int xCord, const int yCord,
				const char counter) const
{
	int x = xCord;
	int y = yCord;

	if (( x >=0 && x < rowSize) && (y >=0 && y < columnSize)
			&& (grid[x][y].holds() == counter))
	{
		switch(direction)
		{
			case 1:			y++; break;
			case 2:	x++;	y++; break;
			case 3:	x++;       break;
			case 4:	x++;	y--; break;
			case 5:			y--; break;
			case 6:	x--;	y--; break;
			case 7:	x--;	     break;
			case 8:	x--;	y++; break;

			default: cerr << "Interna Napaka 1" << endl;
		}
		return 1+ checkForWin(direction, x, y, counter); // this is recirsive call
	}
	else
		return 0;
}

void Board::display() const
{
    system("cls");//clrscr();
    cout << "Izvirno kodo je napisal Inder Mohan Singh" << endl;
    cout << "Prevedel Bojan Dreu, oktobra 2003" << endl;
    cout << "Ce najdes kaksne napake prosim javi na e-mail: imsb69@yahoo.com" << endl;
    cout << endl;
    cout << endl;
    cout << endl;
	cout << "   " ;
	for (int i=1; i <=columnSize; i++)
		cout << i << "   " ;
	cout << endl;

	for(int j= rowSize-1; j >=0; j--)
	{
		cout << " | ";
		for(int k=0; k < columnSize; k++)
		{
			grid[j][k].display();
			cout << " | ";
		}
		cout << endl;
	}
	for(int m=rowSize; m >=0; m--)
		cout << "----";
	cout << "--" << endl << endl;


}

Game::Game()
{
	Counter :: setTokenNum();		// set static
	state = PLAY;					// contestants can play
	num =0;
	board.display();  				// display the board
}

void Game:: play()
{
	while (state==PLAY)
	{

		int move = contestant[num].getMove(True);
		while(board.moveOkForColumn(move) == False)
			move= contestant[num].getMove(False);
		board.dropInColumn(move, contestant[num].getCounter());

		board.display();
		state = board.situation(); // board returns its current state i.e.
											// the state of play

		if (state == PLAY)
				num = (num +1) % NUM_PLAYERS;
		else
			contestant[num].announce(state);

	}
}

    

gorNa vrh



Hangman.cpp - Vislice:


//Hangman Game
//Vislice
//Prevod: Bojan Dreu

#include <iostream.h> 
#include <stdlib.h> 
#include <conio.h>
#include <stdio.h> 
#include <fstream.h> 
#include <string.h> 


inline void type_of_word(char f); 


int main() 
{   char c,h,ch,ch1,ch2; 
    char word[25]; 
    char word2[25]; 

    int l,i,ng,n,k,x; 

do{
    do
    {system("cls");//clrscr();
        c='\0'; 
        //cout<<"\n\t\t    *********** H A N G M A N ***********\n\n\n";
        cout<<"\n\t\t    ***********************"; //dodal
        cout<<"\n\t\t    *    V I S L I C E    *";
        cout<<"\n\t\t    * Prevedel Bojan Dreu *"; //dodal
        cout<<"\n\t\t    ***********************\n\n\n"; //dodal

        //cout<<"(E) Enter a word\n\n(C) Computer chooses word\n\n(A) Add new word to list\n\n(Q) Quit\n\n\nEnter your choice (E - C - A - Q): ";
        cout<<"(E) Vtipkaj besedo\n\n(C) Racunalnik izbere besedo\n\n(A) Dodaj novo besedo na seznam\n\n(Q) Izhod\n\n\nVtipkaj tvojo izbiro (E - C - A - Q): ";

        cin>>ch2; 
    }while (ch2!='C' && ch2!='c' && ch2!='E' && ch2!= 'e' && ch2!='Q' && ch2!= 'q'&& ch2!='A' && ch2!= 'a');

    if (ch2 == 'Q' || ch2=='q')  exit (0); 

    if (ch2 == 'C' || ch2=='c') 

    { 
        //ifstream fin("hangword.txt");
        ifstream fin("vislice_seznam_besed.txt");
        if(!fin) { system("cls");//clrscr();
        //cout<<"\n\n\n\t\tFile missing, aborting.\n\n\n\nYou are missing a file of name:       hangword.txt \n\n\nLocate it, then place it next to the program file.\n\n\n\n\n\n\n\n\n\n"; system("pause"); return 0;}
        cout<<"\n\n\n\t\tDatoteka manjka, prekinitev.\n\n\n\nManjka ti datoteka z imenom:  vislice_seznam_besed.txt \n\n\nNajdi jo, nato jo namesti zraven programa Hangman.exe.\n\n\n\n\n\n\n\n\n\n"; system("pause"); return 0;}
        for (i=0;!fin.eof();i++)
        {fin>>c; fin.getline(word,25);}
        fin.close();

        do { 
        x=rand(); 
        }while(x>i || x<0); 

        //ifstream finn("hangword.txt");
        ifstream finn("vislice_seznam_besed.txt");
        for (i=0;!finn.eof();i++)
        {finn>>c; finn.getline(word,25); if (x==i) break;}
        finn.close();
    } 

  if (ch2 == 'A' || ch2=='a') 

    { 
       system("cls");// clrscr(); 
       //ofstream fout("hangword.txt",ios::app);
       ofstream fout("vislice_seznam_besed.txt",ios::app);

        if(!fout) {system("cls");//clrscr(); 
        //cout<<"File missing, aborting.\n\nYou are missing a file of name **hangword.txt**\n\nLocate it, then place it next to the program file.\n\n"; system("pause"); return 0;}
        cout<<"\n\n\n\t\tDatoteka manjka, prekinitev.\n\n\n\nManjka ti datoteka z imenom:  vislice_seznam_besed.txt \n\n\nNajdi jo, nato jo namesti zraven programa Hangman.exe.\n\n\n\n\n\n\n\n\n\n"; system("pause"); return 0;}
        cin.get();
        //cout<<"Choose the topic of your word\n\n(M) Movie\n\n(A) Animal\n\n(P) Sport\n\n(S) Song\n\nEnter your choice (A-P-S-M) : ";
        cout<<"Izberi podrocje za tvojo besedo\n\n(M) Filmi\n\n(A) Zivali\n\n(P) Sport\n\n(S) Pesmi\n\nVtipkaj tvojo izbiro (A-P-S-M) : ";
        cin>>h;
        cin.get(); 
        system("cls");//clrscr(); 
        //cout<<"\n\nThe word should not exceed 25 letters\n\nEnter the word : ";
        cout<<"\n\nBeseda ne sme presegati 25 crk !\n\nVtipkaj besedo : ";
        cin.getline(word,25);
        fout<<h<<word<<endl; 
        fout.close(); 
    }


   if (ch2 == 'E' || ch2=='e') 
     {system("cls");// clrscr(); 
       cin.get(); 
       //cout<<"\t\t\t Type the word :  ";
       cout<<"\t\t\t Vtipkaj besedo :  ";
       cin.getline (word, 25);
     } 
if (ch2 == 'E'  || ch2=='e' || ch2 == 'C' || ch2=='c') 
{ 
l=strlen(word); 
char choosen[25]="\0"; 
n=0;k=0; 
system("cls");//clrscr(); 


for(i=0;i<=24;i++) 
   { 
    if (word[i]=='\0') {word2[i]='\0';break;} 
    if (word[i]==' ')  {word2[i]=' ';  n++;} 
    if (word[i]!=' ')  word2[i]='-'; 
   } 
   ng=l+2-n;     //only 2 guesses extra
   do{system("cls");//clrscr(); 
   there:  type_of_word(c); 
     //if (k!=0)  cout<<"\n\n\t\t\tChoosen letters : "<<choosen<<"\n";
     if (k!=0)  cout<<"\n\n\t\t\tZe izbrane crke :  "<<choosen<<"\n";
     //cout<<"\n\n\n\t\t\t      "<<word2<<"\n\n\nYou have "<<ng<< " guesses left, choose a letter : ";
     cout<<"\n\n\n\t\t\t      "<<word2<<"\n\n\nImas "<<ng<< " poskusov na voljo, izberi crko : ";
     cin>>ch; cin.get();
     for (i=0;i<25;i++) if (choosen[i]==ch) {system("cls");//clrscr(); 
     //cout<<"\a\t\t     !!You have choosen "<<ch<<" already!!\n";goto there;}
     cout<<"\a\n\n\t\t P O Z O R  !!  Crko  "<<ch<<"  si ze izbral !!\n\n\n";goto there;}
     ng--; choosen [k]=ch; choosen [k+1]=',';k+=2;



     for (i=0;i<=24;i++)    if (word[i]==ch || word[i]==ch+32 || word[i]==ch-32) word2[i]=ch; 
     //if (!strcmpi (word2,word)) {cout<<"\n\n\n\t\t\t      "<<strupr(word)<<"\n\n\n\n\n\t\t\tCongratulations  :-)\n"; break;}
     if (!strcmpi (word2,word)) {cout<<"\n\n\n\t\tIskana beseda je bila :     "<<strupr(word)<<"\n\n\n\n\n\t\t\t   Cestitam  :-)\n"; break;}

    }while(ng>0 || !strcmpi (word2,word)); 


//if (strcmpi (word2,word))  cout<<"\n\n\nSorry, maybe next time.\n\n\n\n\nThe word was : "<<strupr(word)<<endl;
if (strcmpi (word2,word))  cout<<"\n\n\nOprosti, morda bos uspesen kdaj drugic.\n\n\n\n\nIskana beseda je bila :     "<<strupr(word)<<endl;
}

//cout<<"\n\n\nWould you like to play again??? (Y - N) : ";
cout<<"\n\n\nBi rad ponovno igral ??? (Y - N) : ";
cin>>ch1;  cin.get();

}while (ch1=='y' || ch1=='Y'); 
      //cout<<"\n\n\n";   //odstranil
      //system("PAUSE");  //odstranil
      return 0; 
} 




inline void type_of_word(char f) 

{
     //if (f=='m') cout<<"\n\t\t\t\tMOVIE";
     if (f=='m') cout<<"\n\t\t\t\tFILMI";
     //if (f=='a') cout<<"\n\t\t\t\tANIMAL";
     if (f=='a') cout<<"\n\t\t\t\tZIVALI";
     //if (f=='p') cout<<"\n\t\t\t\tSPORT";
     if (f=='p') cout<<"\n\t\t\t\tSPORT";
     //if (f=='s') cout<<"\n\t\t\t\tSONG";
     if (f=='s') cout<<"\n\t\t\t\tPESMI";
}

    


vislice_seznam_besed.txt:


aara
mcvetje v jeseni
mne joci peter
azebra
aslon
akakadu
pboks
pnogomet
pkosarka
scela ulica nori
phelp
mOj kozarcek moj
azajec 
aopica 
sja ka pa ti tu delas 
mdvorana skrivnosti 
mgospodar prstanov 
mkekec 
phokej 
prokomet 
mmumija 
mmatrica 
mumri pokoncno 
mlevji kralj 
mtarzan 
akaca 
aovca 
akoza 
stam tam tam 
ptenis 
amedved 
mv vrtincu 
psmuk 
psmucarski skoki 
sna golici 
podbojka 
pnamizni tenis 
psmucanje 
pjudo 
mgladiator 
mking kong 
msreca na vrvici 
mvrocica sobotne noci 
mlepotica in zver 
sti si moje sonce 
aslon
sne mi dihat za ovratnik
shelp
akrava

    

gorNa vrh



Business Card Program.cpp - Vizitka:


/***************************************************************************
Business Card Program Tutorial

Copyright 2001 Blazon Resources
http://members.home.net/blazonres

Email questions or comments to:
blazonres@home.com

A tutorial on how to print data using an array.
Substituting 'setw()' to replace printing " " from the <iomanip.h>
	library can clean up the code a little bit, but this way is easier
	for beginners.

	Enjoy!

***************************************************************************/
#include <iostream.h>
#include <string.h>		//Includes data for 'strlen'
#include <stdio.h>

void centerData(char info[], int &j);

void main()
{
	char name[40];		//An array to hold name
	char jobTitle[40];	//An array to hold job title
		
	//Get the Name and job title
	cout << "Enter your name.\n";
	cin.getline(name, 40, '\n');	//Formatted as ('string to save to', 'Maximum length of string', 'When to stop reading the input (here is on a newline)')
	cout << "Enter your job title.\n";
	cin.getline(jobTitle, 40, '\n');

	for (int i = 1; i <= 10; i++)	//Create horizontal lines 1 at a time
	{
		for (int j = 1; j <= 60; j++)
		{
			if (i == 1)			//Top bar
				cout << "_";
			else if (i == 10)	//Bottom bar
				cout << "~";
			else
			{
				if ((j == 1) || (j == 60))	//Bar on left and right
					cout << "|";
				else if ((i == 5) && (j == 2))			//Add name
					centerData(name, j);
				else if ((i == 6) && (j == 2))			//Add job title
					centerData(jobTitle, j);
				else									//Add a space
					cout << " ";
			}
		}
		cout << endl;									//End the current line
	}
 getchar();
}

void centerData(char info[], int &j)	//Center the name or job title, note: j is passed by reference and the changes to it are sent back to 'main'
{
	int lengthString;					//Length of name is stored here

	lengthString = strlen(info);		//Gets the length of the name

	for (j = 2; j < 30 - (lengthString / 2); j++)	//Loop enough spaces to center name
													//Starts on 2nd space of line goes until halfway - half the length of the string

		cout << " ";								//Adds one space to space it

	j += lengthString - 1;							//Adjustment made to j to make the "|   |"'s of the line match up

	cout << info;									//Actually show the name or title on the line

}

    



DomovNA MENI                  1   2   3   4   5   Naslednja »


Vi ste   .  obiskovalec te strani.

gorNa vrh


Datum zadnje spremembe: 19.03.2008.       Copyright © 2006-2012 dr.eu.       Vse pravice pridržane.       Valid HTML 4.01 Transitional