منتخب بازارچه

سورس های نوشته شده به زبان C و ++C

>-->O

همکار بازنشسته
سلام بر کاربران پی تی
از آنجائیکه زبان سی یک زبان پایه محسوب میشود برای برنامه نویسی و در اکثر دانشگاه ها به عنوان درسی 3 واحدی تدریس میگردد تصمیم بر آن گرفتم در این مکان و تاپیک یکسری سورس کد به زبان های سی و سی پلاس پلاس قرار بدهم
امیدوارم مورد توجه دوستان قرار بگیرد و مورد استفاده
 

>-->O

همکار بازنشسته
دفتر تلفن ساده همراه با کلاس ها

کد:
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
 
//=====================================
//=====================================
struct address {
       char name[30] ;
       char street[30] ;
       char city[20] ;
       char state[3] ;
       char number[14] ;
       struct address *next ;
       struct address *prior ;
} list_entry ;
//=====================================
//=====================================
struct address *start ;
struct address *last ;
 
void enter() , display() , search() ;
void list() , del();
void display(struct address *info, int *row);
 
struct address *find(char *);
int menu_select();
struct address *store(struct address *, struct address *);
//=====================================
//=====================================
 
 
 
 
//****************
 
int menu_select()
{
      char s[5];
      system("cls");
      gotoxy(25,4) ;
      printf("1. enter a name ") ;
      gotoxy(25,6) ;
      printf("2. delete a name ") ;
      gotoxy(25, 8) ;
      printf("3. list all files ") ;
      gotoxy(25, 10) ;
      printf("4. search ") ;
      gotoxy(25, 12) ;
      printf("5. quit ") ;
      do {
      gotoxy(20, 18) ;
      printf("enter your select--power By majid (1-5):");
      gets(s);
      } while (atoi(s) < 0 || atoi(s) > 5) ;
      return atoi(s) ;
}
//*********************
 
 
void enter ()
{
   struct address *info ;
   int i ;
   char ch ;
   system("cls") ;
   gotoxy(3, 2) ;
   printf("   name        street     city     state    number");
   gotoxy(3, 3) ;
   printf(" ------------ -------- ");
   printf("--------   -----  ------- ");
   i = 4 ;
   for (;;) {
     info = (struct address *)malloc(sizeof(list_entry)) ;
     if(!info) {
    printf("\n out of memory. press a key ") ;
    getch();
    return ;
     }
     gotoxy(3, i) ;
     gets(info -> name) ;
     if (!info -> name[0]) {
      gotoxy(15, i + 1) ;
      printf("press a key to continue");
      getch() ;
      break ;
     }//end of if
     gotoxy(18, i);
     gets(info -> street) ;
     gotoxy(28, i) ;
     gets(info -> city) ;
     gotoxy(38, i) ;
     gets(info -> state) ;
     gotoxy(45, i) ;
     gets(info -> number) ;
     i++ ;
     start = store(info, start) ;
     } /* entry loop */
    }
//**************
 
 
struct address *store(struct address *i, struct address *top)
{
   struct address *old, *p ;
   if(last == NULL) {
    i -> next = NULL ;
    i -> prior = NULL ;
    start = i;
    last = i ;
    return i ;
   }
   p = top ;
   old = NULL ;
   while (p != NULL) {
       if(strcmp(p -> name, i -> name) < 0) {
          old = p ;
          p = p -> next ;
       }//end of if
       else {
         if (p -> prior) {
          p -> prior -> next=i ;
          i -> next=p ;
          i -> prior=p -> prior;
          p -> prior=i ;
          return top ;
         }//end of if
         i -> next = p ;
         i -> prior = NULL ;
         p -> prior = i ;
         return i ;
       }//end of if
   } // end of while
   old -> next = i ;
   i -> next = NULL ;
   i -> prior = old ;
   last = i ;
   return start ;
}
//******************
 
 
void del()
{
   struct address *info;
   char name[80];
   gotoxy(20, 20) ;
   printf(" enter name for delete : ") ;
   gets(name) ;
   info = find(name) ;
   if(info == NULL) {
       gotoxy(10, 20) ;
       printf(" name not found! press a key to continue.");
       getch() ;
   }
   if (info)
     if (start == info)
    {
      start = info -> next ;
      if(start)
         start -> prior = NULL ;
      else
         last = NULL ;
    } //end of if
     else  {
       info -> prior -> next = info -> next;
       if(info != last)
         info -> next -> prior = info -> prior;
       else
        last = info -> prior ;
     } //end of else
     free(info) ;
     gotoxy(10,20) ;
     printf("name deleted, press a key to continue.");
     getch() ;
}
//*******************************
 
 
struct address *find(char *name)
{
     struct address *info ;
     info = start ;
     while(info != NULL) {
    if (strcmp(name, info -> name) == 0)
       return info;
    info = info -> next ;
     }
     return NULL ;
}
//*****************
 
 
void list ()
{
    struct address *info ;
    int i ;
    info = start ;
    system("cls") ;
    gotoxy(3, 2) ;
    printf("   name        street     city     state    number");
    gotoxy(3, 3) ;
    printf(" ------------ --------  -");
    printf("-------   -----  ------- ");
    i = 4 ;
    while(info != NULL) {
    display(info, &i) ;
    info = info -> next ;
    }
    gotoxy(15, i + 2) ;
    printf("press a key to continue.");
    getch() ;
}
//*******************
 
 
void display(struct address *info, int *row)
{
      gotoxy(3, *row) ;
      printf("%s", info -> name) ;
      gotoxy(18, *row) ;
      printf("%s", info -> street) ;
      gotoxy(28, *row) ;
      printf("%s", info -> city) ;
      gotoxy(38, *row) ;
      printf(info -> state) ;
      gotoxy(47, *row) ;
      printf(info -> number) ;
      *row = *row + 1 ;
}
//**************************
 
 
void search()
{
     char name[40] ;
     int i ;
     struct address *info;
     gotoxy(20, 20) ;
     printf(" enter name to find : ");
     gets(name) ;
     info = find(name) ;
     if(info == NULL) {
      gotoxy(10, 20) ;
      printf(" name not found! press a key to continue.");
      getch() ;
     }//end of if
     else  {
          system("cls") ;
          gotoxy(3, 2) ;
          printf("   name        street   city     state   number");
          gotoxy(3, 3) ;
          printf(" ------------ -------");
          printf("-  --------   -----  ------- ") ;
          i = 4 ;
          display(info ,&i) ;
          gotoxy(15, i + 2) ;
          printf("press a key to continue.");
          getch() ;
     }//end of else
}
//*********************
 
int main()
{
       start = last = NULL ;
       for(;;) {
         switch(menu_select()) {
           case 1:  enter();  break ;
           case 2 : del();    break ;
            case 3:  list() ;  break ;
           case 4:  search(); break ;
           case 5:  exit(0) ;
 
        }//end of switch
       }//end of for
}//end of main
 

>-->O

همکار بازنشسته
مشخصات دانشجویان با امکان ورود اطلاعات حذف اطلاعات و جستجو

کد:
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
 
 
struct student{
    char name[20];
    char family[25];
    int id;
    student *next;
};
student *first,*last;
//////////////////////////
void input(){
student *temp=new student;
cout<<"plese enter the id : "<<endl;
cin>>temp->id;
cout<<"plese enter the name : "<<endl;
cin>>temp->name;
cout<<"plese enter the family : "<<endl;
cin>>temp->family;
if (first==NULL){
    first=last=temp;
}
else {
    temp->next=last;
    last=temp;
}
}
/////////////////////////////////
void output(){
student *temp=new student;
temp=first;
while(temp!=NULL){
    cout<<temp->id<<endl;
    cout<<temp->name<<endl;
    cout<<temp->family<<endl;
    cout<<"*************************************";
    temp=temp->next;
}
cout<<"end of record"<<endl;
}
/////////////////////////////////////
void search(int id){
student *temp=new student;
int find;
temp=first;
while(temp!=NULL){
    if (id==temp->id){
        cout<<temp->id<<endl;
        cout<<temp->name<<endl;
        cout<<temp->family<<endl;
        find=1;
        break;
        }
    else{
        find=0;
        temp=temp->next;
        }
}
    if (find==0){ cout<<"not find record"<<endl;}
}
////////////////////////////////////
void main(){
int stat;
for (;;){
system("cls");
cout<<"***************************************"<<e  ndl;
cout<<"num 1 for input data " <<endl;
cout<<"num 2  for list data " <<endl;
cout<<"num 3 for search data " <<endl;
cout<<"num 4 for exit" <<endl;
cout<<"***************************************"<<e  ndl ;
cin>>stat;
system("cls");
switch(stat){
    case 1:
        input();
        break;
    case 2:
        output();
        break;
    case 3:
        int key;
        cout<<"plese enter id for search : " ;
        cin>>key;
        search(key);
        break;
    case 4:
        exit(0);
}
}
}
 

>-->O

همکار بازنشسته
این کد را که به اول برنامه اضافه کنید برنامه از قسمت application شما در task manager پاک می شود و به قسمت process ها می رود


کد:
//compile with visual c++ 6
 
 
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
 
void main() {
    HWND hWnd;
    AllocConsole();
    hWnd = FindWindowA("ConsoleWindowClass",NULL);
    ShowWindow(hWnd,0);
}
 

>-->O

همکار بازنشسته
برنامه کوچکی که عملکرد تابع scanf و cscanf رو در خواندن داده ها(رشته ای و عددی) شرح میده و باهم مقایسه میکند.

کد:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void clrscr(void)
{system("cls");//in unix os , command is "clear"
}
int main(void){
int x,y;
char t='a';
char m[30],z[30];
for(;;){
printf("\n***************Press Any Key To Start Program********************:");
getch();
clrscr();
   t++;
printf("\ntest the scanf function:");
scanf("%d",&x);//agar voroodi be soorate:[1223 5Enter] bashad
printf("\nx=%d",x);//inja [1223] chap mishavad
printf("\n test the cscanf function:");//dar in tabe amale kelidhaye Enter va Space moadele ham ast(yani payane voroodi)
cscanf("%d",&y);//inja [y] az voroodi gerefte mishavad 
printf("\ny=%d",y);//[y ]chap mishavad
printf("\n test the scanf function in strings:");
scanf("%s",m);/*dar inja adade [5] dar reshte gharar migirad ,zira dar buffer in etelaat mojood ast:[5Enter](bad az 5 moadele ascii enter ast) 
hala tabe scanf adade 5 ra mikhanad va be enter miresad va payane khandan anjam migirad*/
printf("\n m=%s",m);//dar inja charactere 5 chap mishavad !!!
printf("\n test the cscanf function in strings:");
cscanf("%s",z);//kelidhaye space va enter dar in tabe moadele ham ast
printf("\nz=%s",z);//reshte[z] chap mishavad
getch();
}
//stack...
}
 

>-->O

همکار بازنشسته
کتابخانه با امکان ورود - ویرایش- حذف -به امانت گرفتن و پس دادن کتاب

کد:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
 
//===========================
//===========================
class book
{
 friend class library;
 
 private:
    char book_name[11];
    char explain[51];
    char aouther[11];
    char part;
 
    char user[11];    
     int reserved;
 
    book *next;
 
 public:
         book();
    void edit();
    void reserv();
    void getback();
}
//---------------------------
     book::book()
    {
     clrscr();
 
     cout<<"============ add a new book =================="
         <<"\n\nto insert new book ,enter flow informations:"
         <<"\n\nbook name?";
     gets(book_name);
     book_name[10]=NULL;
 
     cout<<"\naouther name?";
     gets(aouther);
     aouther[10]=NULL;
 
     cout<<"\nany explain?";
     gets(explain);
     explain[50]=NULL;
 
     part=book_name[0];
 
     reserved=0;
 
     next=NULL;
 
     cout<<"\n\ninformathions set!";
     getch();
    }
//---------------------------
void book::edit()
    {
cout<<"error ";
    }
//---------------------------
void book::reserv()
    {
     clrscr();
     cout<<"\n=========== reserving book ===================";
 
     if(reserved==0)
        {
         cout<<"\n\nuser name?";
         gets(user);
         user[11]=NULL;
 
         reserved=1;
        }
 
     if(reserved==0)
        {
         cout<<"\n\nsorry! book has been reserved befor"
             <<"by user:";
         puts(user);
        }
 
     getch();
    }
//---------------------------
void book::getback()
    {
     reserved=0;
 
     cout<<"\n\nbook got bak.";
     getch();
    }
//===========================
//===========================
class library
{
 public:
          library();
     void run_menu();
 
 private:
     book *parts[24];
     void insert(book*);
     void find();
     void search();
 
}
//---------------------------
     library::library()
    {
     for(int i=0;i<=23;i++)
        parts[i]=NULL;
 
    }
//---------------------------
void library::run_menu()
    {
 
     char ch='n';
 
     while(ch!='4')
        {
         clrscr();
 
         cout<<"================= LIBRARY =================="
             <<"\n\n1:add a new book."
             <<"\n2:find a book."
             <<"\n3:search a book."
             <<"\n4:exit."
             <<"press numbers:";
 
 
         ch=getch();
 
 
         if(ch=='1')
            {
             book *n=new book;
             insert(n);
            }
         if(ch=='2')
            {
             find();
            }
         if(ch=='3')
            {
             search();
            }
 
        }//while
    }
//---------------------------
void library::insert(book *s)
    {
     int d=s->part-97;
 
     if(parts[d]==NULL)
        {
         parts[d]=s;
        }
     else
        {
         book *p=parts[d],*q;
         while(p!=NULL && strcmp(p->book_name,s->book_name)<0)
            {
             q=p;
             p=p->next;
            }
         q->next=s;
         s->next=p;
        }
 
    }
//---------------------------
void library::find()
    {
     clrscr();
 
     cout<<"=========== edit / delete books ============"
         <<"\nenter exact book name:";
     char name[11];
     gets(name);
     name[11]=NULL;
     int d=name[0]-97;
 
     book *p=parts[d],*q;
     while(p!=NULL && strcmp(p->book_name,name)!=0)
        {
         q=p;
         p=p->next;
        }
     if(p==NULL)
        {
         cout<<"not found!";
        }
     if(p!=NULL)
        {
         cout<<"\n\ndelete it?('d')  or edit?('e')"
             <<"  or reserv?('r')   or getback?('g') :";
         char ch=getch();
         if(ch=='d')
             {
              q->next=p->next;
              delete p;
             }
         if(ch=='e')
             {
              p->edit();
             }
         if(ch=='r')
             {
              p->reserv();
             }
         if(ch=='g')
            {
             p->getback();
            }
        }
     getch();
    }
//---------------------------
void library::search()
    {
     char ch='6';
 
     while(ch!='4')
        {
         clrscr();
         cout<<"================== SEARCH ===================";
         cout<<"\n\n1:search for name."
             <<"\n2:search for aouther."
             <<"\n3:search for explanations."
             <<"\n4:back to main menu.(press numbers)";
 
         ch=getch();
 
         if(ch=='1')
            {
             cout<<"\n\nenter exact name:";
             char name[10];
             gets(name);
             name[11]=NULL;
 
             int d=name[0]-97;
             book *p=parts[d];
             while(p!=NULL && strcmp(p->book_name,name)!=0)
                {
                 p=p->next;
                }
             if(p==NULL)
                {
                 cout<<"\nnot founded!";
                }
             else
                {
                 cout<<"\n\n";
                 cout<<"name:";puts(p->book_name);
                 cout<<"aouther:";puts(p->aouther);
                 cout<<"explain:";puts(p->explain);
                 if(p->reserved==1)
                    {
                     cout<<"RESERVED by:";
                     puts(p->user);
                    }
                 else
                    {
                     cout<<"NOT RESERVES";
                    }
                }//else
             getch();
            }//1
         if(ch=='2')
            {
             cout<<"\n\nenter exact aouther name:";
             char name[11];
             gets(name);
             name[11]=NULL;
             int f=0;
 
             for(int i=0;i<=23;i++)
               {
                book *p=parts[i];
                while(p!=NULL)
                {
                 if(strcmp(p->aouther,name)==0)
                    {
                     f++;
                     cout<<"\n"<<f<<":";
                     cout<<"name:";puts(p->book_name);
                     cout<<"aouthor:";puts(p->aouther);
                     cout<<"explain:";puts(p->explain);
                     if(p->reserved==1)
                        {
                         cout<<"RESERVED BY";
                         puts(p->user);
                        }
                     else
                        {
                         cout<<"NOT RESERVED";
                        }
                    }
 
                 p=p->next;
                }//while
               }
             getch();
            }//2
         if(ch=='3')
            {
             cout<<"\n\nenter key(15char):";
             char name[16];
             gets(name);
             name[15]=NULL;
             int f=0;
 
             for(int i=0;i<=23;i++)
               {
                book *p=parts[i];
                while(p!=NULL)
                {
                 char *tokenptr;
                 tokenptr=strtok(p->explain," ");
                 while(tokenptr!=NULL)
                    {
                     if(strcmp(tokenptr,name)==0)
                        {
                         f++;
 
                         cout<<"\n"<<f<<":";
                         cout<<"name:";puts(p->book_name);
                         cout<<"aouthor:";puts(p->aouther);
                         cout<<"explain:";puts(p->explain);
                         if(p->reserved==1)
                             {
                              cout<<"RESERVED BY";
                              puts(p->user);
                             }
                         else
                             {
                              cout<<"NOT RESERVED";
                             }
                        }
                     tokenptr=strtok(NULL," ");
                    }
 
                 p=p->next;
                }//while
               }//for i
             getch();
            }//3
 
        }
 
    }
//===========================
//===========================
 int main()
    {
     clrscr();
 
     library l1;
     l1.run_menu();
 
     return(0);
    }
 

MihanV

مدیر بخش سیستمهای مدیریت محتوای وب سایت
مدیر انجمن
سورس هایی که تو نت نیست رو بزار
 

>-->O

همکار بازنشسته
سورس تبدیل عدد به حروف در سی پلاس پلاس

کد:
#include <iostream.h>
#include <conio.h>

int main()
{
RE:clrscr();
int s=0,i2=0,x[99];
char y[99]={0};
//Daryaft Adad
cout<<"Lotfan yek adad Vared Konid:\n";
do
{
i2++;
y[i2]=getche();
}while(y[i2]!=13);
i2--;
//Tashkhis Argham
for(register int i=1;i2>=1;i2--)
{
x[i]=y[i2]-48;
i++;
}
i--;
//Namayesh Adad
clrscr();
cout<<"Adad Shoma: ";
for(register int i3=i;i3>=1;i3--)
cout<<x[i3];
cout<<endl<<"Hasel:\n";
//Tarjome adad be horof
for(;i>=1;i--)
{
if(s==1)
{
switch(x[i])
{
case 0:cout<<"";break;
case 1:cout<<"yazdah ";break;
case 2:cout<<"davazdah ";break;
case 3:cout<<"sizdah ";break;
case 4:cout<<"chahardah ";break;
case 5:cout<<"panzdah ";break;
case 6:cout<<"shanzdah ";break;
case 7:cout<<"hevdah ";break;
case 8:cout<<"hejdah ";break;
case 9:cout<<"nozdah ";break;
}
s=0;
}
else
{
if(i%3==2)
{
switch(x[i])
{
case 0:cout<<"";break;
case 1:s=1;break;
case 2:cout<<"bisto ";break;
case 3:cout<<"sio ";break;
case 4:cout<<"chehelo ";break;
case 5:cout<<"panjaho ";break;
case 6:cout<<"shasto ";break;
case 7:cout<<"haftado ";break;
case 8:cout<<"hashtado ";break;
case 9:cout<<"navado ";break;
}
}
else
{
switch(x[i])
{
case 0:cout<<"";break;
case 1:cout<<"yek ";break;
case 2:cout<<"do ";break;
case 3:cout<<"se ";break;
case 4:cout<<"chahar ";break;
case 5:cout<<"panj ";break;
case 6:cout<<"shesh ";break;
case 7:cout<<"haft ";break;
case 8:cout<<"hasht ";break;
case 9:cout<<"noh ";break;
default:goto ESC;
}
}
}
if((x[i+2]==0&&x[i]==0)||(x[i]==0&&x[i-2]==0))
{
cout<<"";
}
else
{
if(i%3==0)
cout<<"sado ";
else if(i==4)
cout<<"hezaro ";
else if(i==7)
cout<<"miliono ";
else if(i==10)
cout<<"triliardo ";
ESC:
}
}
gotoxy(0,22);
cout<<endl<<endl<<"Lotfan kelidi ra baraye tarjome adadi digar feshar dahid"<<endl;
getch();
goto RE;
}

//end
 

>-->O

همکار بازنشسته
بازی اسنک

کد:
#include<iostream.h>
#include<graphics.h>
#include<iomanip.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
#include<stdio.h>
#include<time.h>

void main()
{
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "//bgi");


clock_t start,end,r;
  int x,y,i,x1,y1,j,l,m,temp,tail,col,scr,scr1,tempo;

char scrn[10];
// char key=0;
  temp=30;tail=3;
   scr1=0;
int a[300],b[300];
  i=y=x=0;


const char up='w';
const char dw='s';
const char ls='a';
const char rs='d';

cout<<"  RULES FOR THE GAME"<<endl;
cout<<"KEYS---"<<endl<<"  w- FORWARD"<<endl<<"  a- LEFT TURN"<<endl<<"  d- RIGHT TURN"<<endl<<"  s- DOWN"<<endl;
cout<<"  Q- QUIT"<<endl;
cout<<"  TURN CAPS LOCK OFF"<<endl;
cout<<"  EAT THE INSECTS N LIVE...U DIE IF U CROSS THE LIMIT / MOVE OVER UR SELF /"<<endl;
cout<<"  CROSS UR LEFTOVER SKIN."<<endl;
cout<<"  SHEADS SKIN AFTER REGULAR INTERVALS.."<<endl;
cout<<"  KEEP MOVING TO FIND FOOD ELSE U DIE"<<endl;
cout<<"	 POINTS ARE ADDED FOR EVERY INSECT YOU EAT,BUT EAT THE FIRST ONE BEFORE SECOND ONE COMES UP ELSE NO SCORE WILL BE ADDED UP"<<endl<<endl;
cout<<"  PRESS MOVE(a) KEY TO CONTINUE.....";
getch();

cleardevice();
setbkcolor(9);
for(j=0;j<=7;j++)
a[j]=b[j]=0;

rectangle(20,21,600,441);
outtextxy(20,5,"SCORE..");
randomize();
l=(random(520)+60);
if(l<=99)
{l=l/10;
l=l*10;}
else {l=l/10;
l=l*10;  }

m=(random(400)+40);
if(m<=99)
{m=m/10;
m=m*10; }
else {m=m/10;
m=m*10;  }
outtextxy(l,m,"*");

char key;
do

{

setcolor(15);
rectangle(20,21,600,440);
if(i==60||i==120||i==190||i==270)
{
l=(random(520)+50);
if(l<=99)
{l=l/10;
l=l*10;}
else {l=l/10;
  l=l*10;  }

m=(random(400)+30);
if(m<=99)
{m=m/10;
m=m*10; }
else {m=m/10;
  m=m*10;  }

setcolor(15);
outtextxy(l,m,"ى");
sound(3800);

 }

start=clock();
 key=getch();
   end=clock();
    r=end-start;
   if(r>=15)
    { outtextxy(100,100,"YOU ARE TOO SLOW...:-( ");
    delay(1000);nosound();break;}

if (i==300 )
{ i=0;}

{
 if(key==up)
 { y-=10;}
 if(key==dw)
 { y+=10;}
  if(key==ls)
 { x-=10;}
  if(key==rs)
 { x+=10;}
  }
  setcolor(10);
 a[i]= x1=210+x;
 b[i]= y1=210+y;
if(x1==l && y1==m)
 { scr1++;
 scr=10*scr1;
 sprintf(scrn,"%d",scr);
   nosound();
   setcolor(0);
outtextxy(70,5,"غغ");
setcolor(15);
outtextxy(70,5,scrn);

  temp+=10;tail++; }

if(x1==20||x1==600||y1==20||y1==440)
{nosound();break;}

col=getpixel(x1,y1);
if(col>0)
  break;
  nosound();
  tempo=tail;

 if(i>=(299-tempo))
{ setcolor(4);
 tempo--  ;
}
 outtextxy(x1,y1,"X");
  setcolor(0);
  outtextxy(a[i-tail],b[i-tail],"X" );
i++;


} while (key !='q');

settextstyle(2,0,26);
outtextxy(210,210,"OUT");
 getch();
closegraph();

}
 

>-->O

همکار بازنشسته
تغییر رنگ نوشته متن :

کامپایلر : Borland C++ 5.02

کد:
#include <iostream>
#include <conio>
int main(){
for(int i=1;i<=4;i++){
textcolor(i+8);
cprintf("Welcome to C++ World");
cout<<endl;}
getch();
}
 

>-->O

همکار بازنشسته
برنامه ی مغلوب عدد طبیعی n

کد:
#include<iostream.h>
Main()
{
Int n,d,s=0;
Cout<<”please inter n”;
Cin>>n;
While(n>0){
D=n%10; 
N=n\10;
S=s*10+d;
}cout<<s;
}
 

>-->O

همکار بازنشسته
یک برنامه که یک پشته را پیاده سازی می کند و یه سری اطلاعات را داخل پشته میریزد و بعد دوباره آنها را خارج می کند

کد:
#include <stdio.h>
#include <conio.h>
int top;
struct stack
{
    int data;
    struct stack *next;
};
bool isempty(struct stack *x)
{
    if(!top) return true;
    else return false;
}
 
int pop(struct stack *x,bool rm) 
{    if(!isempty(x))
    {
        struct stack *y=x;
        for(int i=0;i<top-1;i++) x = x->next;
        int data = x->data;
        if(rm)
        {
            for(int i=0;i<top-2;i++) y = y->next;
            y->next = NULL;
            x = y;
            top--;
        }
        return data;
    }else
    {
        printf("It is Empty!");
        return 0;
    }
}
void push(struct stack *x,int data) 
{
    for(int i = 0;i<top;i++) x = x->next;
    x->data = data;
    x->next = new struct stack;
    top++;
}
int main() 
{
    top = 0;
    struct stack *t = new struct stack;
    push(t,1);
    push(t,2);
    push(t,3);
    printf("%d",pop(t,true));
    printf("%d",pop(t,false));
    printf("%d",pop(t,true));
    printf("%d",pop(t,false));
    printf("%d",pop(t,false));
    getch();
    return 0;
}
 

>-->O

همکار بازنشسته
این برنامه یه عدد میگیره و میگه اول هست یا نه و بعد تمام مقسوم علیه ها و همچنین مقسوم علیه های اول عدد رو به کاربر میگه
کد:
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
int isprime(int);
main()
{
int n=0,div[999],sh=0,pdiv[999],count=0,s=0;
error:
cout<<"Please insert a number : "<<"\n";
cin>>n;
if(n<=0)
    {
        clrscr();
        cout<<"You are just aloud to enter numbers wich are bigger than 0 (zero) ! Please try again . OK ?"<<"\n";
        n=0;
        goto error;
    }
for(int i=1;i<=n;i++)
    {
        if((n%i)==0)
            {
                div[sh]=i;
                sh++;
            }
    }
if(sh==2)
    {
        cout<<"*******************************************  *******"<<"\n";
        cout<<"This number is prime and has 2 divisors :"<<"\n "<<char(26)<<" {1 , "<<n<<"}"<<"\n";
      cout<<"*******************************************  *******"<<"\n";
        getch();
        exit(1);
    }
else if(sh==1)
    {
        cout<<"*******************************************  *******"<<"\n";
        cout<<"This number has ony 1 divisor :"<<"\n "<<char(26)<<" {1}"<<"\n";
        cout<<"*******************************************  *******"<<"\n";
        getch();
        exit(1);
    }
else
    {
        cout<<"*******************************************  *******"<<"\n";
        cout<<"This number is not prime and has "<<(sh)<<" divisors :"<<"\n "<<char(26)<<" {";
        for(int j=0;j<sh;j++)
            {
                if(j==(sh-1))
                    {
                        cout<<div[j]<<"}"<<"\n";
                        goto con;
                    }
                cout<<div[j]<<" , ";
            }
    }
con:
for(int k=0;k<sh;k++)
    {
        s=isprime(div[k]);
        if(s!=0)
            {
            pdiv[count]=s;
         s=0;
            count++;
            }
        else
            s=0;
    }
cout<<" "<<char(26)<<" Prime divisors : {";
for(int u=0;u<count;u++)
    {
        if(u==(count-1))
            {
                cout<<pdiv[u]<<"}"<<"\n";
                cout<<"*******************************************  *******"<<"\n";
                getch();
                exit(1);
            }
        cout<<pdiv[u]<<" , ";
    }
}
//==================================================  ============================
int isprime(int a)
{
int pri=0;
for(int r=1;r<=a;r++)
    {
        if((a%r)==0)
            pri++;
    }
if(pri==2)
    return a;
else
    return 0;
}
 

>-->O

همکار بازنشسته
دفترچه تلفن با روش فايلينگ همراه امكاناتي چون درج ويرايش حذف جستجو ليست كردن و ...
 

فایل های ضمیمه

>-->O

همکار بازنشسته
تشخیص متقارن بودن پارانتزها (به ازای هر پارانتز باز ، یک پارانتز بسته وجود دارد) با استفاده از پشته ها (STL)

کد:
#include <iostream>
#include <conio>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main(){
string str = "(2+3*(5+6/2))+(3/(6+7*3))";
stack<char,vector<char>> s;
for(int i=0;i<str.size();i++){
 if(str[i]=='(')
  s.push('(');
  if(str[i]==')')
  s.pop();}
  if(s.empty())
  cout<<"True \n";
  else
  cout<<"False \n";
  getch();
  }
 

>-->O

همکار بازنشسته
این برنامه تمام جایگشت های یک لیست عدد رو می دهد


کد:
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <string>
#include <sstream> 
#include <stack>
#include <queue>
#include <map> 
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <functional>
#include <cstdio>
#include <ctime>
using namespace std ; 
int main () {
    //freopen ("in.in","r",stdin) ;
    int n ; cin >> n ;// number of inputs 
    vector <int> v (n) ; 
    for(int i = 0 ; i < n;i ++) cin >> v [i] ; 
    sort (v.begin(),v.end()) ; 
    do {
        for(int i = 0 ; i < n;i ++){ 
            if (i) printf (" ") ; 
            printf ("%d",v [i]) ; 
        } 
        printf ("\n"); 
    }while (next_permutation (v.begin(),v.end())) ; 
}
 
بالا