نمایش نتایج 1 تا 40 از 320

نام تاپیک: مجموعه برنامه های نوشته شده به زبان C و ++C

Hybrid View

پست قبلی پست قبلی   پست بعدی پست بعدی
  1. #1

    نقل قول: مجموعه برنامه های نوشته شده به زبان C و ++C

    یه دفتر چه تلفن با قابلیت ( اضافه کردن ، حذف ، مرتب سازی ، جست و جو ، نمایش ، ذخیره سازی در فایل ) :
    // Count.cpp : Defines the entry point for the console application.
    //

    #include "stdafx.h"
    #include "iostream"
    #include "fstream"
    #include "string.h"
    #include "conio.h"
    using namespace std;

    struct PhoneBookObject
    {
    char FirstName[20];
    char LastName[20];
    char PhoneNumber[20];
    };

    void Add(PhoneBookObject PhoneBook[],int &NumObject,bool &Change)
    {
    cout<<"\nFirst Name : ";
    cin.getline(PhoneBook[NumObject].FirstName,19);

    cout<<"\nLast Name : ";
    cin.getline(PhoneBook[NumObject].LastName,19);

    cout<<"\nPhon Number : ";
    cin.getline(PhoneBook[NumObject].PhoneNumber,19);

    NumObject++;

    Change=1;
    }

    void Sort(PhoneBookObject PhoneBook[],int NumObject,bool &Change)
    {
    PhoneBookObject Temp;

    for(int i=0;i<NumObject;i++)
    for(int j=0;j<NumObject-i-1;j++)
    if(strncmp(PhoneBook[j].LastName ,PhoneBook[j+1].LastName,19)>0)
    {
    Temp=PhoneBook[j];
    PhoneBook[j]=PhoneBook[j+1];
    PhoneBook[j+1]=Temp;
    }

    Change=1;
    }

    void Show(PhoneBookObject PhoneBook[],int NumObject)
    {
    for(int i=0;i<NumObject;i++)
    cout<<"\n"<<i<<") "<<PhoneBook[i].FirstName<<" "<<PhoneBook[i].LastName<<"\tTel: "<<PhoneBook[i].PhoneNumber;
    }

    int Search(PhoneBookObject PhoneBook[],int NumObject)
    {
    char Input[20];
    int Index=-1;
    cout<<"\nLast Name : ";
    cin.getline(Input,19);

    for(int i=0;i<NumObject;i++)
    if(strstr(PhoneBook[i].LastName,Input))
    {
    Index=i;
    break;
    }

    if(Index!=-1)
    {
    cout<<"\nFirst Name: "<<PhoneBook[Index].FirstName<<"\tLast Name: "<<PhoneBook[Index].LastName<<"\tTel: "<<PhoneBook[Index].PhoneNumber;
    return Index;
    }
    else
    {
    cout<<"\n\""<<Input<<"\" Not Find!";
    return Index;
    }
    }
    void Save(PhoneBookObject PhoneBook[],int NumObject,bool &Change)
    {
    ofstream ofile;
    ofile.open("c:\\PhoneBook.txt");

    if(Change==1)
    {
    ofile<<NumObject;
    for(int i=0;i<NumObject;i++)
    ofile<<"\n"<<PhoneBook[i].FirstName<<"\n"<<PhoneBook[i].LastName<<"\n"<<PhoneBook[i].PhoneNumber;

    cout<<"\nSaved!";

    Change=0;
    }
    else
    cout<<"\nPhone Number Save befor!";
    }


    void Delete(PhoneBookObject PhoneBook[],int &NumObject,bool &Change)
    {
    int Find;
    char Sure;
    Find=Search(PhoneBook,NumObject);

    if(Find!=-1)
    {
    cout<<"\nAre You Sure to Delete this Number(yes/no)?";
    Sure=getch();
    switch(Sure)
    {
    case 'y':
    {
    for(int i=Find;i<NumObject-1;i++)
    PhoneBook[i]=PhoneBook[i+1];

    NumObject--;
    Change=1;

    break;
    }

    case 'n':
    break;

    default : cout<<"\nWrong Character!";
    }
    }

    }

    void Exit(char &Input,PhoneBookObject PhoneBook[],int NumObject,bool &Change)
    {
    char Sure;
    if(Change==1)
    {
    cout<<"\nDo you want to seva the phone Number before Exit on Program(yes/no)?";
    Sure=getch();
    switch(Sure)
    {
    case 'y':
    {
    Save(PhoneBook,NumObject,Change);
    break;
    }
    case 'n':
    break;
    default : cout<<"\nWrong Character!";
    }
    }

    cout<<"\nAre you sure to exit on program(yes/no)?";
    Sure=getch();
    switch(Sure)
    {
    case 'y':
    break;

    case 'n':
    Input='0';
    break;
    default : cout<<"\nWrong Character!";
    }
    }


    void main()
    {
    PhoneBookObject PhoneBook[20];
    int NumObject=0;
    bool Change=1;
    char Input=0;

    ifstream ifile;
    ifile.open("c:\\PhoneBook.txt");
    ifile>>NumObject;

    for(int i=0;i<NumObject;i++)
    {
    ifile>>PhoneBook[i].FirstName;
    ifile>>PhoneBook[i].LastName;
    ifile>>PhoneBook[i].PhoneNumber;
    }

    cout<<" *---* Welcome to your Phone Book *---*";

    while(Input!='7')
    {
    cout<<"\n1)Add\n2)Delete\n3)Sort\n4)Show\n5)Search \n6)Save\n7)Exit";

    cout<<"\nPlease enter number of your act : ";

    Input=getch();

    switch(Input)
    {
    case '1':Add(PhoneBook,NumObject,Change);
    break;

    case '2':Delete(PhoneBook,NumObject,Change);
    break;

    case '3':Sort(PhoneBook,NumObject,Change);
    break;

    case '4':Show(PhoneBook,NumObject);
    break;

    case '5':Search(PhoneBook,NumObject);
    break;

    case '6':Save(PhoneBook,NumObject,Change);
    break;

    case '7':Exit(Input,PhoneBook,NumObject,Change);
    break;

    default:cout<<"\n *---* The input character is wrong!*---*\n\n";
    }
    }
    }

  2. #2
    کاربر دائمی آواتار voiceoffox
    تاریخ عضویت
    مهر 1389
    محل زندگی
    مشهد
    پست
    122

    Cool نقل قول: مجموعه برنامه های نوشته شده به زبان C و ++C

    سلام
    اینم بازی "سنگ - کاغذ - قیچی" هست ! اما با بازی سنگ و کاغذ و قیچی که چند صفحه قبل یکی نوشته بود فرق هایی داره!

    این بازیتک نفره اس و فقط شمایین با کامپیوتر ! یه جورایی هوشمنده !

    #include<iostream.h>
    #include<conio.h>
    #include<stdlib.h>
    int mantegh(int,int);
    main()
    {
    randomize();
    int pcp=0,hup=0,mon=0,sel=0,pcsel=0,ans=0;
    error1:
    cout<<"Choose your round mode by pressing the number of mode wich you want :"<<"\n";
    cout<<"(This will be the number of rounds wich you play)"<<"\n";
    cout<<"0. <1>Round"<<"\n"<<"1. <3>Rounds"<<"\n"<<"2. <5>Rounds"<<"\n";
    cout<<"3. <10>Rounds"<<"\n"<<"4. <15>Rounds"<<"\n"<<"5. <20>Rounds"<<"\n";
    cout<<"6. <25>Rounds"<<"\n"<<"7. <50>Rounds"<<"\n"<<"8. <75>Rounds"<<"\n";
    cout<<"9. <100>Rounds"<<"\n";
    cout<<"Now ! insert the numbr of your mode :"<<"\n";
    mon=getche();
    if(mon=='0')
    mon=1;
    else if(mon=='1')
    mon=3;
    else if(mon=='2')
    mon=5;
    else if(mon=='3')
    mon=10;
    else if(mon=='4')
    mon=15;
    else if(mon=='5')
    mon=20;
    else if(mon=='6')
    mon=25;
    else if(mon=='7')
    mon=50;
    else if(mon=='8')
    mon=75;
    else if(mon=='9')
    mon=100;
    else
    {
    clrscr();
    cout<<"Just press the number of mode , nothing else ! OK ?"<<"\n";
    goto error1;
    }
    cout<<"\n"<<"Ok !"<<" Remmember that you must reach to htis point !"<<"\n";
    cout<<"press any key to start the game ..."<<"\n";
    getch();
    clrscr();
    for(int i=1;i<=mon;i++)
    {
    error2:
    cout<<"Press the number of the thing that you wantb to use :"<<"\n";
    cout<<"1. Sang"<<"\n"<<"2. Kaghaz"<<"\n"<<"3. Gheychi"<<"\n";
    sel=getch();
    if(sel=='1')
    {
    clrscr();
    cout<<"******************************"<<"\n";
    cout<<"Your selection : <SANG>"<<"\n";
    }
    else if(sel=='2')
    {
    clrscr();
    cout<<"******************************"<<"\n";
    cout<<"Your selection : <KAGHAZ>"<<"\n";
    }
    else if(sel=='3')
    {
    clrscr();
    cout<<"******************************"<<"\n";
    cout<<"Your selection : <GHEYCHI>"<<"\n";
    }
    else
    {
    clrscr();
    cout<<"You are just aloud to enter numbers 1 or 2 or 3 ! OK ?"<<"\n";
    goto error2;
    }
    pcsel=((rand()%3)+1);
    if(pcsel==1)
    cout<<"Computer selection : <GHEYCHI>"<<"\n";
    else if(pcsel==2)
    cout<<"Computer selection : <SANG>"<<"\n";
    else
    cout<<"Computer selection : <KAGHAZ>"<<"\n";
    ans=mantegh(pcsel,sel);
    if(ans==1)
    {
    cout<<"====="<<"\n"<<"No added point !"<<"\n";
    cout<<"Computer points : "<<pcp<<"\n"<<"Human points : "<<hup<<"\n";
    }
    else if(ans==2)
    {
    cout<<"====="<<"\n"<<"Player gained the point !"<<"\n";
    ++hup;
    cout<<"Computer points : "<<pcp<<"\n"<<"Human Points : "<<hup<<"\n";
    }
    else if(ans==3)
    {
    cout<<"====="<<"\n"<<"Computer gained the point !"<<"\n";
    ++pcp;
    cout<<"Computer points : "<<pcp<<"\n"<<"Human Points : "<<hup<<"\n";
    }
    else
    {
    clrscr();
    goto error2;
    }
    cout<<"******************************"<<"\n";
    }
    if(pcp==hup)
    {
    clrscr();
    cout<<"##########################################" <<"\n";
    cout<<"# There wasn't any winner in this game ! #"<<"\n";
    cout<<"##########################################" <<"\n";
    cout<<" *Computer points : "<<pcp<<"\n"<<" *Player points : "<<hup<<"\n";
    }
    else if(pcp>hup)
    {
    clrscr();
    cout<<"##########################################" <<"\n";
    cout<<"# Computer won this game ! #"<<"\n";
    cout<<"##########################################" <<"\n";
    cout<<" *Computer points : "<<pcp<<"\n"<<" *Player points : "<<hup<<"\n";
    }
    else if(hup>pcp)
    {
    clrscr();
    cout<<"##########################################" <<"\n";
    cout<<"# Player won this game ! #"<<"\n";
    cout<<"##########################################" <<"\n";
    cout<<" *Computer points : "<<pcp<<"\n"<<" *Player points : "<<hup<<"\n";
    }
    else
    getch();
    }
    int mantegh(int com,int man)
    {
    if((com==2 && man=='1')||(com==3 && man=='2')||(com==1 && man=='3'))
    return 1;
    //No one didn't take the point !
    else if((com==1 && man=='1')||(com==2 && man=='2')||(com==3 && man=='3'))
    return 2;
    //Human took the point !
    else if((com==1 && man=='2')||(com==2 && man=='3')||(com==3 && man=='1'))
    return 3;
    //Computer took the point !
    else
    return 0;
    }


    کامپایل شده تحت Turbo C++‎ 4.5
    آخرین ویرایش به وسیله voiceoffox : جمعه 24 دی 1389 در 13:07 عصر دلیل: یه نقص فنی کوچولو !

برچسب های این تاپیک

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •