-
پاسخ : پروژه هاي برنامه نويسي
برنامه ضرب رو با استفاده از جمعهای متوالی و تابع بازگشتی
کد PHP:
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
int c;
int add(int a,int b)
{
if(b==0)
return c;
else
c+=a;
return add(a,b-1);
}
int main()
{
int a,b;
cin>>a;
cin>>b;
cout<<add(a,b)<<endl;
}
-
پاسخ : پروژه هاي برنامه نويسي
کد PHP:
#include <iostream.h>
#include <graphics.h>
#include <fstream.h>
#include <conio.h>
#include <stdlib.h>
#include <dos.h>
#include <stdio.h>
struct U{
unsigned char magic[2];
}mag;
struct master {
// word bftype;
unsigned long Size;
unsigned short Reserved;
unsigned short Reserved2;
unsigned long BitsOffset;
} HEADER;
class info {public:
unsigned long header_sz;
unsigned long width;
unsigned long height;
unsigned short nplanes;
unsigned short bitspp;
unsigned long compress_type;
unsigned long bmp_bytesz;
unsigned long hres;
unsigned long vres;
unsigned long ncolors;
// unsigned long nimpcolors;
} INFOHEADER;
huge DetectSvga()
{
return 2;
}
void Show(char* filename,int xcor,int ycor)
{
fstream File;
File.open(filename,ios::in);
char Ch;
File.read((char*)&mag,2);// read te 2 frist byte for know file
/*if (mag.magic!="BM"){
printf("file not a bitmap");
exit(0);
}*/
File.read((char*)&HEADER,12); //read for get offst bye of bitmap data
File.read((char*)&INFOHEADER,40); //read for width , heght and know 8 bit
unsigned int i;
File.seekg(HEADER.BitsOffset);
for(i=0;i<INFOHEADER.height;i++) //This for loop is used to display the bitmap.
{
for(int j=0;j<INFOHEADER.width;j++)
{
File.read(&Ch,1); // Here Ch reads the color of your bitmap.
putpixel(xcor+j,ycor+INFOHEADER.height-i,Ch);//write pixel to screen
}
}
File.close();
}
void main()
{
clrscr();
int gd = DETECT, md, a;
initgraph(&gd,&md,"..\\bgi");
installuserdriver("svga256",&DetectSvga);
char msg[15];
char* k;
cout<<"plz write adress of 8-bit bitmap format file: (example: c:/test.bmp)"<<endl;
cin>>k;
Show(k,100,100);
getch();
}
-
پاسخ : پروژه هاي برنامه نويسي
سه روش برای دسترسی به مقادیر یک آرایه دو بعدی
کد PHP:
void ascendbsort(int column, int *list[][COL_SIZE])
{
int i,j,k;
for(i=0;i<(ROW_SIZE-1);i++)
{
for(j=0;j<(ROW_SIZE-(i+1));j++)
{
if(list[j][column] > list[j+1][column])
{
for(k=0; k < 4; k++)
{
swap(&list[j][k], &list[j+1][k]);//switch the entire row, not just the element
}
}
}
}
}
printf ( "\n" ) ;
}
printf ("\n" ) ;
}
show ( int ( *q )[4], int row, int col )
{
int i, j ;
int *p ;
for ( i = 0 ; i < row ; i++ )
{
p = q + i ;
for ( j = 0 ; j < col ; j++ )
printf ( "%d ", * ( p + j ) ) ;
printf ( "\n" ) ;
}
printf ( "\n" ) ;
}
print ( int q[ ][4], int row, int col )
{
int i, j ;
for ( i = 0 ; i < row ; i++ )
{
for ( j = 0 ; j < col ; j++ )
printf ( "%d ", q[i][j] ) ;
printf ( "\n" ) ;
}
printf ( "\n" ) ;
}
-
پاسخ : پروژه هاي برنامه نويسي
تعویض نام ها با استفاده از آرایه دو بعدی کاراکتری
کد PHP:
main( )
{
char names[ ][10] = {
"akshay",
"parag",
"raman",
"srinivas",
"gopal",
"rajesh"
} ;
int i ;
char t ;
printf ( "\nOriginal: %s %s", &names[2][0], &names[3][0] ) ;
for ( i = 0 ; i <= 9 ; i++ )
{
t = names[2][i] ;
names[2][i] = names[3][i] ;
names[3][i] = t ;
}
printf ( "\nNew: %s %s", &names[2][0], &names[3][0] ) ;
}
-
پاسخ : پروژه هاي برنامه نويسي
کار با آدرس ها در ساختارها
کد PHP:
struct book
{
char name[25] ;
char author[25] ;
int callno ;
} ;
main( )
{
struct book b1 = { "Let us C", "YPK", 101 } ;
display ( &b1 ) ;
}
display ( struct book *b )
{
printf ( "\n%s %s %d", b->name, b->author, b->callno ) ;
}
-
پاسخ : پروژه هاي برنامه نويسي
کد PHP:
#include <iostream>
#include <string>
using namespace std;
char comp(string s){
int i=0,j=0,st=0;
bool flag=false,f2=false;
int sl=s.length();
while(true){
cout<<s[i]<<"-"<<i<<" ";
if(flag){
s[i]='~';flag=false;if(i==st) f2=true;
}else flag=true;
while(s[++i]=='~');
if(f2) {st=i;f2=false;}
if(!s[i]){ i=st;cout<<endl;
}
j++;
if(j>((s.length()-1)*2)) {return s[i];break;}
}
}
void main(){
cout<<"\n this man live : "<<comp("e12345678")<<endl;
}
-
پاسخ : پروژه هاي برنامه نويسي
تابع بازگشتی :
کد PHP:
#include <iostream>
#include <conio>
int Josephios(int n){
if(n==1)
return 1;
else{
if(n%2==1)
return 2*Josephios((n-1)/2)+1;
if(n%2==0)
return 2*Josephios(n/2)-1;
}
}
//==================================
int main(){
int n;
while(true){
cout<<"Enter number of people : \n";
cin>>n;
cout<<"Alive : "<<Josephios(n)<<endl;}
getch();
}
-
پاسخ : پروژه هاي برنامه نويسي
- پیاده سازی الگوریتم کراسکال با سورس کامل برنامه
لینک دانلود فایل اجرایی EXE برنامه DOWNLOAD - پیاده سازی الگوریتم پرایم همراه با سورس کامل برنامه
لینک دانلود فایل اجرایی EXE برنامه
DOWNLOAD - الگوريتم استراسن با حل و سورس کامل برنامه
لینک دانلود فایل اجرایی EXE برنامه
DOWNLOAD
- ماشين حساب مهندسي همراه با سورس کامل برنامه 1
لینک دانلود فایل اجرایی EXE برنامه
DOWNLOAD - ماشين حساب مهندسي همراه با سورس کامل برنامه 2
لینک دانلود فایل اجرایی EXE برنامه
DOWNLOAD
پیاده سازی درخت جستجوی دو دویی Binary Search Tree
لینک دانلود فایل اجرایی EXE برنامه DOWNLOAD
کلیه عملیات ماتريس ها (ضرب ، جمع ، تفريق ، تقسيم ماتريس
مغلوب و ترانهاده و ...)
لینک دانلود فایل اجرایی EXE برنامه
DOWNLOAD
- برنامه دفترچه تلفن (با امکانات حذف - اضافه - جستجو - گزارش
گیری و نمایش )
لینک دانلود فایل اجرایی EXE برنامه
DOWNLOAD
-
پاسخ : پروژه هاي برنامه نويسي
- پروژه هشت وزير شطرنج در 92 حالت مختلف
لینک دانلود فایل اجرایی EXE برنامه
DOWNLOAD پروژه N وزیر شطرنج (هوش مصنوعی) - الگوریتم ژنتیک
لینک دانلود فایل اجرایی EXE برنامه
DOWNLOAD - بازی پازل اعداد PUZZLE به زبان سی پلاس C++
لینک دانلود فایل اجرایی EXE برنامه DOWNLOAD - بازی پازل اعداد PUZZLE به زبان سی C
لینک دانلود فایل اجرایی EXE برنامه DOWNLOAD -پياده سازي كليه روشهاي مرتب سازي
لینک دانلود فایل اجرایی EXE برنامه
DOWNLOAD
- مثلث خيام پاسكال
لینک دانلود فایل اجرایی EXE برنامه
DOWNLOAD
- برنامه دانش آموزان : گرفتن اطلاعات و ذخيره - حذف - اضافه گزارش گيري - جستجو - و ...
لینک دانلود فایل اجرایی EXE برنامه DOWNLOAD - لينك ليست
- بازي مار پله
- برنامه فاكتوريل
- حركت اسب شطرنج
- بازي پارانوئيد - پارانوييد Paranoid
لینک دانلود فایل اجرایی EXE برنامه DOWNLOAD
- يك ماشين حساب خطي با در نظر گرفتن پرانتزها
و تقدم عملگرها
- لینک دانلود فایل اجرایی EXE برنامه DOWNLOAD
-
پاسخ : پروژه هاي برنامه نويسي
- بازي حافظه - در يك پازل بعد از پيدا كردن خانه هايي كه 2 عدد شبيه هم هستند را حذف مي كند
لینک دانلود فایل اجرایی EXE برنامه DOWNLOAD
- حل مسئله رياضي سري تيلور
لینک دانلود فایل اجرایی EXE برنامه DOWNLOAD
- شبيه سازي بازي تانك
لینک دانلود فایل اجرایی EXE برنامه DOWNLOAD
- بازي دوز
dooz لینک دانلود فایل اجرایی EXE برنامه DOWNLOAD
- يك برنامه
ويرايشگر متن اديتور Text Editor مانند اديتور سيستم ويندوز - لینک دانلود فایل اجرایی EXE برنامه DOWNLOAD
- برنامه ي معكوس نمودن عدد ورودي : 124 421
لینک دانلود فایل اجرایی EXE برنامه DOWNLOAD
- برنامه مربع جادويي
- ماتريسي كه جمع سطر و ستونهاي آن و همچنين جمع قطرهاي آن از همه طرف برابر است . لینک دانلود فایل اجرایی EXE برنامه DOWNLOAD
-
پاسخ : پروژه هاي برنامه نويسي
سلام آبجی
خوب میدونید به ما یه پرژه شطرنج دادن که باید با جاوا به صورت انسان با انسان نوشته شه. کار زیادی داره ولی من باید 25 خرداد تحویل بدم . میتونیدکمکی به من کنید . ایمیل من هم اینه :
bad.paeizy@gmail.com
منتظر جواب شما هستم
-
پاسخ : پروژه هاي برنامه نويسي
نقل قول:
نوشته اصلی توسط
usefzadeh
سلام آبجی
خوب میدونید به ما یه پرژه شطرنج دادن که باید با جاوا به صورت انسان با انسان نوشته شه. کار زیادی داره ولی من باید 25 خرداد تحویل بدم . میتونیدکمکی به من کنید . ایمیل من هم اینه :
bad.paeizy@gmail.com
منتظر جواب شما هستم
دوست گرامی باید بگم که هیچ ایمیلی از سمت کادر مدیران سایت علمی نخبگان برای کاربران ارسال نمیشوند
موفق باشید
-
کتابخانه با امکان ورود - ویرایش- حذف -به امانت گرفتن و پس دادن کتاب
کتابخانه با امکان ورود - ویرایش- حذف -به امانت گرفتن و پس دادن کتاب
کد PHP:
#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);
}
-
مشخصات دانشجویان با امکان ورود اطلاعات حذف اطلاعات و جستجو
مشخصات دانشجویان با امکان ورود اطلاعات حذف اطلاعات و جستجو
کد PHP:
#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<<"***************************************"<<endl;
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<<"***************************************"<<endl ;
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);
}
}
}
-
دفتر تلفن ساده با کلاس ها
دفتر تلفن ساده با کلاس ها
کد PHP:
#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
-
اوور لودینگ اپراتورها در کلاس در c++
اوور لودینگ اپراتورها در کلاس در c++
کد PHP:
#include <iostream.h>
#include <string.h>
#include <conio.h>
#include <stdio.h>
class string
{
private:
char text[40];
public:
void show()
{
cout << text << "\n";
}
string operator + (string s)
{
string temp;
strcpy(temp.text, text);
strcat (temp.text, s.text);
return temp;
}
string operator + (char s[])
{
string temp;
strcpy(temp.text, text);
strcat (temp.text, s);
return temp;
}
string operator++()
{
char temp[40];
strcpy(temp , text);
strcat(text,temp);
}
friend string operator +(char s[] , string s2)
{
string temp;
strcpy(temp.text , s);
strcat(temp.text , s2.text);
return temp;
}
string operator =(char s[])
{
strcpy(text , s);
}
string operator =(string s)
{
strcpy(text , s.text);
}
};
void main()
{
string s1 , s2 , s3;
clrscr();
s1 = "Ali";
char temp[]={"Ali"};
s2 = temp;
s3 = "hossein";
s1++;
s1.show();
s1 = temp + s3;
s1.show();
s2 = s1;
s2.show();
s2 = s2 + "azarpevand";
s2.show();
getch();
}
-
اطلاعات عمومی دانشجو
اطلاعات عمومی دانشجو
خصوصیات برنامه:
1)وارد کردن نمره به تعداد دلخواه
2)بازه نمرات بین 0 تا 100
3)مشخص کردن وضعیت نمرات
4)گرفتن میانگین
5)مشخص کردن تعداد افراد قبول و مردود شده
کد PHP:
#include <iostream.h>
#include <conio.h>
int main()
{
float x, counter=1, counterp=0, counterf=0,ave=0,y,m;
cout<<"How many mark? ";
cin>>y;
cout<<"Pass and Fail: ";
cin>>m;
cout<<"#########################################";
cout<<"\n";
while (counter<=y){
cout<<"Mark "<<counter<<": ";
cin>>x ;
counter=counter+1;
ave+=x;
if (x>100){
cout<<"ERROR:FALSE MARK"<<"\n";
cout<<"\n";
cout<<"egain enter the ";
counter=counter-1;
}
else if (x>=m){
cout<<"Pass"<<"\n"<<"*********************"<<"\n"<<"\n";
counterp+=1;
}
else{
cout<<"Fail"<<"\n"<<"*********************"<<"\n"<<"\n";
counterf+=1;
}
}
if (counter=y){
cout<<"Pass number: "<<counterp<<"\n";
cout<<"Fail number: "<<counterf<<"\n";
cout<<"Average: "<<ave/y<<endl;
}
getch();
return 0;
}
-
برنامه رسم خط DDA بزبان ++c
برنامه رسم خط DDA بزبان ++c
کد PHP:
#include
#include
#include
int main()
{
int driver = DETECT,mode;
initgraph(&driver,&mode,"c:\\borlandc\\bgi");
float x1,x2,y1,y2,i;
float ytemp,xtemp;
float m;
cout<<"Enter x1 , y1"<
cin>>x1>>y1;
cout<<"Enter x2 , y2"<
cin>>x2>>y2;
m = (y2-y1)/(x2-x1);
ytemp=y1;
xtemp=x1;
if (m<1){
for (i = 0; i <= x2-x1; i++)
{
putpixel(xtemp,ytemp,4);
ytemp+=m;
xtemp++;
}
}
else
{
for (i=y1; i
{
putpixel(xtemp,i,4);
xtemp=(xtemp*m+1)/m;
}
}
getch();
return 0;
}
-
برنامه رسم دایره برسنهام بزبان ++c
برنامه رسم دایره برسنهام بزبان ++c
کد PHP:
#include
#include
#include
#include
void main()
{
//Detect Graphic Mode
int driver = DETECT,mode;
initgraph(&driver,&mode,"c:\\tc\\bgi");
//Program Start
int xcenter,ycenter,r,x,y,p,i;
cout<<"Enter R"< cin>>r;
xcenter=r;
ycenter=r;
x=0;
y=r;
p=1-r;
putpixel(xcenter+x,ycenter+y,2);
while (x {
x++;
if (p<0)
p+=2*x+1;
else
{
p+=2*(x-y)+1;
y--;
}
putpixel(xcenter+x,ycenter+y,2);
putpixel(xcenter-x,ycenter+y,2);
putpixel(xcenter+x,ycenter-y,2);
putpixel(xcenter-x,ycenter-y,2);
putpixel(xcenter+y,ycenter+x,2);
putpixel(xcenter-y,ycenter+x,2);
putpixel(xcenter+y,ycenter-x,2);
putpixel(xcenter-y,ycenter-x,2);
}
getch();
}
-
برنامه ای که عمل (x AND Y) را انجام میده!
این برنامه ساده دو عدد ورودی را گرفته و عمل x AND Y را انجام داده و نتیجه رو چاپ میکند!
کد PHP:
#include <iostream.h>
int add(int number, int number2)
{
int answer;
_asm{
MOV EAX, number;
MOV EBX, number2;
ADD EAX, EBX;
MOV answer, EAX;
}
return answer;
}
int main(int argc, char* argv[])
{
int number;
int number2;
int answer;
cout << "Enter a number: ";
cin >> number;
cout << "\n\nEnter another number: ";
cin >> number2;
answer = add(number, number2);
cout << "\n\n" << number << " and " << number2 << " is " << answer << endl;
return 0;
}
-
برنامه ای که بکمک آرایه دو عدد 30 رقمی را با هم جمع و ضرب و تفریق میکند:
برنامه ای که بکمک آرایه دو عدد 30 رقمی را با هم جمع و ضرب و تفریق میکند:
کد PHP:
#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
void print(char *);
void main()
{
char n1[31]* n2[31]* n3[32];
int i* carry = 0* sum;
clrscr();
cout << "Enter Number 1 (30 Digits): "; cin >> n1;
cout << "Enter Number 2 (30 Digits): "; cin >> n2;
for (i = 29; i >= 0; i --)
{
sum = n1[i] + n2[i] - 96 + carry;
if (sum > 9)
{
sum -= 10;
carry = 1;
}
else carry = 0;
n3[i+1] = sum + 48;
}
n3[0] = carry;
cout << "Sum: ";
print(n3);
getch();
}
void print(char n[31])
{
int i;
for (i=0; i<31; i++)
{
if (i != 0)
cout << n[i];
else if (n[i]==49)
cout << n[i];
}
}
-
محاسبه ی 1 روی !n تا 60 رقم اعشار
محاسبه ی 1 روی !n تا 60 رقم اعشار
کد PHP:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
main()
{
int q[61],a[61],i,n,s;
printf("\n N ro vared kon ta 1/N! ro hesab konam: ");
scanf("%d",&s);
if(s==1)
{
printf("\n1/1!=1");
getch();
exit (0);
}
for(i=0;i<=60;i++)
{
a[i]=0;
q[i]=0;
}
for(n=2;n<=s;n++)
for(i=0;i<=60;i++)
{
if(n==2 && i==0)
a[0]=1;
q[i]=a[i]/n;
if(q[i]==0)
a[i+1]=a[i]*10+a[i+1];
else
a[i+1]=(a[i]%n)*10+a[i+1];
a[i]=q[i];
}
printf("\n 1/%d!= 0.",s);
for(i=1;i<=60;i++)
printf("%d",a[i]);
getch();
return 0;
}
-
برنامه يک بر روی e تا ۵۰ اقم اعشار
برنامه يک بر روی e تا ۵۰ اقم اعشار
کد PHP:
#include<stdio.h>
#include<conio.h>
void main()
{
long int n;
int i,su[51],sm[51],sum[51],x,y,k,w,q[51],a[51];
clrscr();
for(i=0;i<=50;i++)
{
su[i]=0;
sm[i]=0;
a[i]=0;
q[i]=0;
sum[i]=0;
}
for(n=2;n<=1000000;n++)
{
if(n==2)
a[0]=1;
for(i=0;i<=50;i++)
{
q[i]=a[i]/n;
if(q[i]==0)
a[i+1]+=a[i]*10;
else
a[i+1]+=(a[i]%n)*10;
a[i]=q[i];
}
for(i=50;i>=0;i--)
{
if(n%2==0)
{
su[i]+=a[i];
x=su[i]%10;
y=su[i]/10;
if(y!=0)
{
su[i]=x;
su[i-1]+=y;
}
}
else if(n%2!=0)
{
sm[i]+=a[i];
w=sm[i]%10;
k=sm[i]/10;
if(k!=0)
{
sm[i]=w;
sm[i-1]+=k;
}
}
}
}
for(i=50;i>=0;i--)
{
if(su[i]>=sm[i])
sum[i]=su[i]-sm[i];
else if(su[i]<sm[i])
{
sum[i]=10+su[i]-sm[i];
su[i-1]=su[i-1]-1;
}
}
printf("0.");
for(i=1;i<=50;i++)
printf("%d",sum[i]);
getch();
}
-
پاسخ : پروژه هاي برنامه نويسي
اين برنامه زيرمجموعه های يک مجموعه را به شما نشان می دهد. روش کارش هم اينجوريه که اول بايد تعداد اعضای مجموعه را مشخص کنيد .
بعدش هم اعضای مجموعه رو يکی يکی وارد کنيد .
بعد از زدن اينتر زير مجموعه ها مشخص می شوند .
کد PHP:
#include <stdio.h>
#include <conio.h>
#include<math.h>
int main()
{
int i,j,m,n;
clrscr();
printf("enter number : ");
scanf("%d",&n);
char a[100];
for(i=0;i<n;i++)
{
printf("x%d=",i+1);
scanf("%d",&a[i]);
}
for(j=0;j<pow(2,n);j++)
{
m=j;
printf("{");
for(i=0;i<=j;i++)
{
if(m%2==1)
{
printf("%d",a[i]);
printf(",");
m=(m-1)/2;
}
else m=m/2;
}
printf("}\n");
}
getch();
return 0;
}
-
پروژه lineeditor
پروژه LINEEDITOR
با این LINEEDITOR می تونید کارهایی مانند ویرایش کلمات حذف insert و یا هر کاری که مربوط به ویرایش است انجام بدید.این برنامه فقط در محیط tc قابل اجراست
کد PHP:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#define LEN 10
#define SCAPE 27
#define RIGHT 77
#define LEFT 75
#define BACKSPACE 8
#define DELETE 83
#define END 79
#define HOME 71
#define INSERT 82
#define ISCONTROL 0
#define CtrL 12
#define CtrR 18
#define CtrY 25
#define CtrO 15
#define CtrS 19
#define TAB 9
//***********************************************
class LineEditor{
private:
int X,Y,Index,IsInsert,Numchar;
char ch,A[1000],S[12];
void Updatescreen(void){
int i,savepos=wherex()-X;
Peykan();
gotoxy(X,Y);
for(i=Index-savepos;i<Index-savepos+LEN;i++)
if(Numchar>i)
cprintf("%c",A[i]);
else
cprintf(" ");
gotoxy(X+savepos,Y);
}
/************************************************/
void Home (void){
Index=0;
gotoxy(X,Y);
}
/************************************************/
void End (void){
Index=Numchar-1;
if(Numchar<LEN-1){
gotoxy(X+Numchar-1,Y);
}
else{
gotoxy(X+LEN-1,Y);
}
}
/************************************************/
int Left (void){
if(Index==0)
return 0;
Index--;
if(wherex()>X)
gotoxy(wherex()-1,Y);
return 1;
}
/***********************************************/
int Right(void){
if(Index>Numchar-2)
return 0;
Index++;
int k=wherex();
if(k<X+LEN-1)
gotoxy(k+1,Y);
return 1;
}
/************************************************/
void Delete (void){
if(Index<Numchar-1){
for(int i=Index;i<Numchar;i++)
A[i]=A[i+1];
Numchar--;
}
}
/************************************************/
void Insert(char ch){
for(int i=Numchar-1;i>=Index;i--)
A[i+1]=A[i];
A[Index]=ch;
Numchar++;
Right();
}
/************************************************/
void Backspace(void){
if (Left())
Delete();
}
/************************************************/
void Overwrite(char ch){
if(Index==Numchar-1)
Insert(ch);
else{
A[Index]=ch;
Right();
}
}
/************************************************/
void clearleft(void){
int i,savepos=wherex()-X;
for(i=savepos;i>=0;i++)
Backspace();
gotoxy(X,Y);
}
/***********************************************/
void clearright(void){
Index++;
int c=Numchar-Index,i;
for(i=0;i<=c;i++)
Delete();
Index--;
}
/************************************************/
void clear(void){
clearright();
clearleft();
if(Numchar!=1)
Delete();
}
/************************************************/
void save(char S[]){
FILE *fp;
if ((fp=fopen(S,"wb"))==NULL){
gotoxy(X-30,Y+3);
printf("\ncannot open fill...");
getch();
exit(1);
}
fwrite(&A,2*strlen(A),1,fp);
gotoxy(X,Y);
clear();
fclose(fp);
open(S);
}
/************************************************/
void open (char S[]){
FILE *fp;
if ((fp=fopen(S,"rb"))==NULL){
gotoxy(X-30,Y+3);
gotoxy(X,Y);
}
fread(A,sizeof(A),1,fp);
Numchar=strlen(A)+1;
End();
fclose(fp);
}
//**********************************************
void Peykan (void){
int b=wherex();
int a=X+LEN-wherex();
if(Index==0){
gotoxy(X-1,Y);
cprintf(" ");
gotoxy(X,Y);
}
if(Numchar-Index-1>a){
gotoxy(X+LEN,Y);
cprintf("%c",16);
gotoxy(b,Y);
}
else{
gotoxy(X+LEN,Y);
cprintf(" ");
gotoxy(b,Y);
}
if(Index>LEN-1){
gotoxy(X-1,Y);
cprintf("%c",17);
gotoxy(b,Y);
}
if(wherex()-X<Index){
gotoxy(X-1,Y);
cprintf("%c",17);
gotoxy(b,Y);
}
}
//***********************************************
public:
LineEditor(int x,int y,char *s){
X=x;
Y=y;
Numchar=1;
IsInsert=0;
Index=0;
A[Numchar-1]='\0';
strcpy(S,s);
}
//***********************************************
void DetectKeyGo(void){
End();
Updatescreen();
while((ch=getch())!=SCAPE){
if (ch=='\r')
continue;
if((ch==ISCONTROL) || (ch==BACKSPACE) || (ch==CtrL) || (ch==CtrR) || (ch==CtrY) || (ch==CtrS) || (ch==CtrO) || (ch==TAB)){
if(ch==ISCONTROL)
ch=getch();
switch(ch){
case TAB: End();
if(Y<29) gotoxy(X,Y+5);
else gotoxy(X,Y-10);
return;
case END:End(); break;
case LEFT:Left(); break;
case HOME:Home(); break;
case CtrY:clear(); break;
case CtrS:save(S); break;
case CtrO:open(S); break;
case RIGHT:Right(); break;
case DELETE:Delete(); break;
case CtrL:clearleft(); break;
case CtrR:clearright(); break;
case BACKSPACE:Backspace(); break;
case INSERT:IsInsert++;
}}
else if (IsInsert%2==0)
Insert(ch);
else
Overwrite(ch);
Updatescreen();
} exit(0);
}
//************************************************
void Drawline (void){
textbackground(1);
textcolor(4);
gotoxy(X-1,Y);
for(int i=1;i<=LEN+2;i++)
cprintf(" ");
gotoxy(X,Y);
}
};
//***********************************************
void MYNAME(void){
textcolor(7);
gotoxy(26,5);
printf(" << In The Name Of God >>");
gotoxy(25,10);
printf(" << mohammad hadi moghaddami >>");
}
//***********************************************
int main(){
LineEditor L1(33,20,"LineE1.txt"),L2(33,25,"LineE2.txt"),L3(33,30,"LineE3.txt");
textbackground(0);
clrscr();
MYNAME();
L3.Drawline();
L2.Drawline();
L1.Drawline();
while(1){
L1.DetectKeyGo();
L2.DetectKeyGo();
L3.DetectKeyGo();
}
return 0;
}
-
برنامه هك مموري ويندوز
اين برنامه بسيار ساده است فقط در كامپايلر هاي تحت ويندوز مثل Microsoft Visual C قابل اجراست!!
کد PHP:
#include <iostream>
#include <windows.h>
#include <cstdlib>
using namespace std;
void Hax(int*address)
{
short int random=NULL;
DWORD proc_id;
random = rand();
HWND hWnd = FindWindow(NULL,"MEMORY HAX");
GetWindowThreadProcessId(hWnd,&proc_id);
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS,false,proc_id);
WriteProcessMemory(hProcess,(LPVOID)address,&random,1,NULL);
}
int main()
{
system("Title MEMORY HAX");
int x = 8;
while(x=x){cout << &x << " \\ " << x << endl;Sleep(500);Hax(&x);}
return 0;
}
-
برنامه ای که رشته ای را در یک فایل جستجو میکند و تکرارهای رشته در فایل را در خروجی چاپ میکند
برنامه ای که رشته ای را در یک فایل جستجو میکند و تکرارهای رشته در فایل را در خروجی چاپ میکند
کد PHP:
#include<iostream.h>
#include<fstream.h>
#include<string.h>
int main(void)
{
char filename [20], str [20] , searchstr [20];
int cont=0;
cout << "Enter FileName :";
cin>>filename;
cout<< "Enter string : ";
cin>> searchstr ;
ifstream in (filename);
if(!in)
{
cout<<"Cannat Open Input File.\n";
return 1;
}
while (!in.eof())
{
in>>str;
if(!strcmp(str,searchstr))
count++;
}
cout<<"found "<<cout;
cout<<"number of times.\n";
in.close();
retun 0;
}
-
برنامه تبدیل بابنری به نوشته!(bin2dic)
این برنامه ساده کد باینری رو از ورودی دریافت کرده و به حالت نوشته نشان میدهد!
کد PHP:
#include <stdio.h>
#include <math.h>
int main(void) {
int dec=0, flag=0.0;
int bin, bit;
double exp=0.0;
printf("Enter a binary number : ");
scanf("%d", &bin);
while(bin) {
bit=bin%10;
if(bit!=0 && bit!=1) {
flag=1;
}
bin=bin/10;
dec=dec+bit*pow(2, exp);
exp++;
}
if(flag) {printf("\n+++ Not a binary number !!!\n");}
else {printf("\n+++ Number in decimal : %d\n", dec);}
return 0;
}
-
پاسخ : پروژه هاي برنامه نويسي
برنامه ای که وقتی اعداد یه ماتریس به برنامه میدیم به ما بگه که این ماتریس هم ارزی هست یا نه و مشخص کنه ویژگی های بازتابی و تقارنی و تعدی رو...
کد PHP:
#include <iostream>
#include <conio>
int main(){
int n;
bool r1,r2,r3;
cout<<"Enter Size of Matrix\n";
cin>>n;
//--------------
int **a=new int*[n];
for(int i=0;i<n;i++)
a[i]=new int[n];
//--------------
cout<<"Enter Your Matrix\n";
for(int i=0;i<n;i++){
for(int j=0;j<n;j++)
cin>>a[i][j];
}
cout<<"___________________________________\n\n";
//--------------
//Baztabi
int f1=0;
for(int i=0;i<n;i++){
if(a[i][i]==1)
f1++;
}
if(f1==n){
cout<<"Baztabi Ast\n\n";
cout<<"-----------------\n";
r1=true;
}
else{
cout<<"Baztabi Nist\n\n";
cout<<"-----------------\n";
r1=false;
}
//--------------
//Tagharoni
int f2=0;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i<j){
if(a[i][j]==a[j][i])
f2++;
}
}
}
if(f2==(((n*n)-n)/2)) {
cout<<"Tagharoni Ast\n\n";
cout<<"-----------------\n";
r2=true;
}
else{
cout<<"Tagharoni Nist\n\n";
cout<<"-----------------\n";
r2=false;
}
//--------------
//Ta-addi
int f3=0;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
for(int k=0;k<n;k++){
if((a[i][j]==1 && a[j][k]==1))
{
if(a[i][k]!=1){
f3++;
break;
}
}
}}}
if(f3==0) {
cout<<"Taaddi Ast\n\n";
r3=true;
}
else{
cout<<"Taaddi Nist\n\n";
r3=false;
}
//--------------
cout<<"________________________________\n\n";
if(r1==true && r2==true && r3==true){
cout<<"Hamarzi Ast\n\n";
cout<<"-----------------\n";}
else{
cout<<"Hamarzi Nist\n\n";
cout<<"-----------------\n";
}
getch();
}
-
برنامه ای که 10 جمله را خوانده تعداد حروف، ارقام و کلمات را تعیین کند
برنامه ای که 10 جمله را خوانده تعداد حروف، ارقام و کلمات را تعیین کند
کد PHP:
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
int words,alphabets,numbers;
void getcount(char s[])
{
int state=0;
char chars[]=" !()*+,./:;<=>?[\\]^`{}~";
for (int pos=0;s[pos];pos++)
{
if (((s[pos]>='A') && (s[pos]<='Z'))
|| ((s[pos]>='a') && (s[pos]<='z')))
{
state=1;
alphabets++;
}
else if ((s[pos]>='0') && (s[pos]<='9'))
{
state=1;
numbers++;
}
else
for (int chpos=0;chars[chpos];chpos++)
if (chars[chpos]==s[pos])
{
if (state)
words++;
state=0;
break;
}
}
if (state)
words++;
}
int main()
{
int i;
char s[500];
clrscr();
words=0;
alphabets=0;
numbers=0;
for (i=0;i<10;i++)
{
cout << "Please enter a text #" << (i+1) << " : " << endl;
gets(s);
getcount(s);
}
cout << endl << "Count of words = " << words << endl;
cout << endl << "Count of alphabet chars = " << alphabets << endl;
cout << endl << "Count of numeric chars = " << numbers << endl;
cout << endl << "Press any key to continue." << endl;
getch();
return 0;
}
-
برنامه ای که دو ماتریس (3 در 4) و (4 در 5) را در هم ضرب کند
برنامه ای که دو ماتریس (3 در 4) و (4 در 5) را در هم ضرب کند
کد PHP:
#include <stdio.h>
#include <conio.h>
void main()
{
int i,j,k;
char matrixA[3][4], matrixB[4][5], matrixC[3][5];
clrscr();
for (i=0;i<3;i++)
for (j=0;j<4;j++)
{
printf("A[%d,%d] = ", i+1, j+1);
scanf ("%d", &matrixA[i][j]);
}
for (i=0;i<4;i++)
for (j=0;j<5;j++)
{
printf("B[%d,%d] = ", i+1, j+1);
scanf ("%d", &matrixB[i][j]);
}
for (i=0;i<3;i++)
for (j=0;j<5;j++)
{
matrixC[i][j]=0;
for (k=0;k<4;k++)
matrixC[i][j]+= matrixA[i][k]*matrixB[k][j];
}
clrscr();
for (i=0;i<3;i++)
{
for (j=0;j<5;j++)
printf("%5d ", matrixC[i][j]);
printf("\n\n");
}
getch();
}
-
برنامه ای که یک عدد لاتین را خوانده و آن را به فارسی تبدیل کند
برنامه ای که یک عدد لاتین را خوانده و آن را به فارسی تبدیل کند
کد PHP:
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
void main()
{
long int n;
ldiv_t d;
int level=0;
int num,i;
char t1000[4][20]={"","hezar","milion","miliard"};
char t100[10][20]={"","yeksad","devist","sisad","chaharsad","pansad",
"sheshsad","haftsad","hashtsad","nohsad"};
char t10[10][20]={"dah","yazdah","davazdah","sizdah","chahardah","panzdah",
"shanzdah","defdah","hejdah","noozdah"};
char t20[10][20]={"","","bist","si","chehel","panjah",
"shast","haftad","hashtad","navad"};
char t1[10][20]={"","yek","do","seh","chahar","panj",
"shesh","haft","hasht","noh"};
char s[80],t[80],u[80];
clrscr();
printf ("Please enter a number : ");
scanf ("%ld", &n);
if (n==0)
strcpy(s,"Sefr");
else
{
strcpy(s,"");
do
{
d = ldiv(n,1000L);
num=(int) d.rem;
n=d.quot;
strcpy(t,t100[num / 100]);
i=num % 100;
if ((i >= 10) && (i <= 19))
{
if (t[0])
strcat(t," o ");
strcat(t,t10[i-10]);
}
else
{
if ((t[0]) && (i >= 20))
strcat(t," o ");
strcat(t,t20[i / 10]);
if (i % 10)
{
if (t[0])
strcat(t," o ");
strcat(t,t1[i % 10]);
}
}
if (t[0])
{
if (s[0])
strcpy(u," o ");
else
strcpy(u,"");
strcat(u,s);
strcpy(s,t1000[level]);
strcat(s,u);
strcat(t,s);
strcpy(s,t);
}
level++;
} while (n);
}
printf ("%s",s);
getch();
}
-
پیاده سازی پشته با لیست پیوندی
پیاده سازی پشته با لیست پیوندی
کد PHP:
#include <iostream>
#include <conio>
struct stack
{
int value;
struct stack *top;
};
void insert(struct stack *,int);
int remove(stack *,bool*);
void print(stack *);
struct stack sample;
int main()
{
char ch;
bool flag=0;
int item,d;
while(1)
{
clrscr();
gotoxy(45,23);
cout<<"*** Writting By Karma ***";
gotoxy(1,1);
cout<<"\n\nWhat do you want to do?\n\n";
cout<<"1-insert\n2-remove\n3-Print\n4-Exit\n\n";
cout<<"What is your selection:";
cin>>ch;
switch(ch)
{
case'1':
clrscr();
cout<<"\n\nPlease neter a number to add:";
cin>>item;
insert(&sample,item);
break;
case'2':
d=remove(&sample,&flag);
if(flag==1)
{
clrscr();
cout<<"\n\nYour deleted number is:";
cout<<d;
getch();
}
break;
case'3':
print(&sample);
getch();
break;
case'4':
return 0;
}
}
getch();
return 0;
}
//***********************************************
void insert(struct stack *p,int item)
{
struct stack*temp;
temp=new struct stack;
temp->value=item;
if(p==0)
p=temp;
else
{
temp->top=p->top;
p->top=temp;
}
}
//***********************************************
int remove(stack *p,bool*flag)
{
int item;
struct stack*temp;
temp=p->top;
if(p==0||p->top==0)
{
clrscr();
cout<<"\nVoid deletion";
getch();
*flag=0;
}
else
{
temp=p->top;
item=temp->value;
p->top=temp->top;
*flag=1;
}
delete temp;
return item;
}
//***********************************************
void print(struct stack*p)
{
int i=0;
struct stack*temp;
temp=p;
while(temp!=0)
{
if(i!=0)
cout<<" <- "<<temp->value;
temp=temp->top;
i++;
}
}
-
دفترچه تلفن ساده
دفترچه تلفن ساده
کد PHP:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <iostream.h>
#include <string.h>
main()
{
menu:
int cm1;
char tn[81];
char view[100];
char add[100];
FILE *fptr;
clrscr();
cout << "Menu: " << "1.Create new phone book\n" << " 2.View or edit phone book\n" << " 3.Quit\n";
cin >> cm1;
switch (cm1)
{
case 1:
clrscr();
cout << "Enter name... Warning! Don't create files with same names.\n";
cin >> tn;
fptr = fopen(tn, "w");
fclose(fptr);
goto menu;
case 2:
goto submenu1;
case 3:
exit(0);
}
submenu1:
clrscr();
cout << "Submenu: 1.View\n 2.Add info.\n 3.Delete info.\n 4.Main menu\n";
cin >> cm1;
switch (cm1)
{
case 1:
goto viewmode;
case 2:
goto addmode;
case 3:
goto deletemode;
case 4:
goto menu;
}
viewmode:
clrscr();
cout << "Enter phone book name...\n";
cin >> tn;
clrscr();
if ((fptr = fopen(tn, "r")) == NULL)
{
printf("Can't open %s, enter any key to go to the submenu.", tn);
cin >> tn;
fclose(fptr);
goto submenu1;
}
while (fgets(view, 100, fptr) != NULL)
fputs(view, stdout);
fclose(fptr);
cout << "\n\nEnter any key to go back to submenu...\n";
getch();
goto submenu1;
addmode:
clrscr();
cout << "What file do you wish to add to?\n";
cin >> tn;
if ((fptr = fopen(tn, "a")) == NULL)
{
printf("Can't open %s, enter any key to go to the submenu.\n",tn);
cin >> tn;
fclose(fptr);
goto submenu1;
}
cout << "Enter the info. you would like to add..\n";
gets(add);
fputs(add, fptr);
fputs("\n", fptr);
fclose(fptr);
goto submenu1;
deletemode:
clrscr();
cout << "Refresh which phone book?\n";
cin >> tn;
if ((fptr = fopen(tn, "w")) == NULL)
{
printf("Can't open %s, enter any key to go to the submenu.\n",tn);
cin >> tn;
fclose(fptr);
goto submenu1;
}
cout << "Done...\n";
getch();
goto submenu1;
}
-
پاسخ : پروژه هاي برنامه نويسي
ماشین حساب گرافیکی که جمع و ضرب و تفریق اعداد تا 128 رقم رو میتونه خیلی سریع حساب کنه ( ماشین حساب ویندوز تا 32 رقم اجازه میده ) .
کد این برنامه رو به صورت خیلی ساده و با استفاده از آرایه ها نوشتم. از تابع ضرب اون برای حساب کردن فاکتوریل اعداد بزرگ نیز میشه استفاده کرد. و برای قسمت گرافیکی آن به ناچار از Turbo C++ 3.0 استفاده کردم.
کد PHP:
#include <graphics.h>
#include <conio.h>
#include <iostream.h>
#include <stdlib.h>
#include <dos.h>
#define ESC 0x1b
#define EXIT 120
void draw(void);
void getArray( int[],char& );
void printArray( int[] );
void reverseArray( int[] );
void plus(int[], int[], int[]);
void minus(int[], int[], int[]);
void multiple(int[], int[], int[] );
void initgraph();
void animate( char );
void wellcome(void);
void error(void);
int main(void)
{
char func='n';
int value1[128] ,
value2[128] ,
result[128] = {0};
initgraph();
wellcome();
draw();
getArray( value1, func );
reverseArray( value1 );
getArray( value2, func );
reverseArray( value2 );
switch( func )
{
case '+':
plus(value1, value2, result);
break;
case '-':
minus(value1, value2, result);
break;
case '*':
multiple(value1, value2, result);
break;
default: cout << "Oh sorry! You made a mistake.";
}
printArray ( result );
if(getch() == ESC )
{
cleardevice();
main();
}
closegraph();
return 0;
}
/*=================Draw===========*/
void draw (void)
{
int x = getmaxx();
int y = getmaxy();
settextstyle(2,HORIZ_DIR,4);
setfillstyle(SOLID_FILL, LIGHTBLUE);
bar(x / 2 - 210, 50, x / 2 + 210, 270);
setfillstyle(SOLID_FILL, WHITE);
bar(x / 2 - 200, 60, x / 2 + 200, 155);
setcolor(BLACK);
line(125,120,x / 2 + 190, 120);
line(125,125,x / 2 + 190, 125);
setfillstyle(SOLID_FILL, BLUE);
setcolor(BLUE);
int Y = 165;
for ( int i = 0; i < 3; i++)
{
int X = 220;
for ( int j = 0; j < 4; j++)
{
bar3d(X,Y,X + 25,Y + 25,3,1);
X += 35;
if ( j == 2 )
X += 15;
}
Y += 35;
}
bar3d(375,165,410,260,3,1);
setcolor(WHITE);
outtextxy(230,172,"1");
outtextxy(265,172,"2");
outtextxy(300,172,"3");
outtextxy(350,172,"+");
outtextxy(230,207,"4");
outtextxy(265,207,"5");
outtextxy(300,207,"6");
outtextxy(350,207,"-");
outtextxy(390,207,"=");
outtextxy(230,242,"7");
outtextxy(265,242,"8");
outtextxy(300,242,"9");
outtextxy(350,242,"x");
}
/*======= initgraph ===============*/
void initgraph()
{
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "C:\\tc\\bgi\\");
}
/*=====================getArray===============*/
void getArray( int value1[], char& func )
{
int xpos = 115, ypos = 65;
if( func != 'n' ) ypos += 3 * textheight("1");
for ( int i = 0; i<128; i++ )
value1[i] = -1;
int digit = 0;
char c;
char* cc;
while(digit < 128)
{
setcolor(BLUE);
c = getch();
animate(c);
if ( c == '+' )
{
func = '+';
outtextxy(125,65 + 2 * textheight("1"),"+");
return;
}
else if ( c == '-' )
{
func = '-';
outtextxy(125,65 + 2 * textheight("1"),"-");
return;
}
else if ( c == '*' )
{
func = '*';
outtextxy(125,65 + 2 * textheight("1"),"x");
return;
}
else if ( (int)c == 13 )
{
return;
}
else if ( c == ESC )
{
cleardevice();
main();
}
else if ( c == EXIT )
{
exit(0);
}
else
value1[digit++] = c - 48;
cc[0] = c;
cc[1] = '\0';
if( digit == 65 )
{
xpos = 115;
ypos += textheight("1");
}
xpos += textwidth("1");
outtextxy(xpos,ypos,cc);
}
return;
}
/*===================printArray=======================*/
void printArray( int value[])
{
int digit = 0, xpos = 115, ypos = 130;
char* cc;
cc[1] = '\0';
char c;
for ( digit = 0; digit < 128 && value[digit] == 0; digit++)
{
}
if ( digit == 127 )
outtextxy(115 + textwidth("1"),130,"0");
for(int count = 0 ; digit < 128; digit++,count++)
{
c = value[digit] + 48;
cc[0] = c;
xpos += textwidth("1");
if ( count == 65 )
{
ypos += textheight("1");
xpos = 121;
}
outtextxy(xpos,ypos,cc);
}
return;
}
/*===================plus=============================*/
void plus(int value1[], int value2[], int result[])
{
for ( int i = 127; i >= 0 && value1[i] >= 0; i-- )
result[i] += value1[i];
for (i = 127; i >= 0 && value2[i] >= 0; i-- )
result[i] += value2[i];
for ( i = 127; i >= 0; i-- )
{
if ( (result[1] / 10) + result[0] > 9 )
error();
if ( result[i] > 9 )
{
result[i-1] += result[i] / 10;
result[i] %= 10;
}
}
}
/*====================reverseArray===============*/
void reverseArray( int a[] )
{
int size = 127, temp;
for ( int i = 0; i < 128; i++ )
{
if ( *(a + i) == -1 )
{
size = i - 1;
break;
}
else
continue;
}
for ( i = 0; i <= size; i++ )
{
temp = *(a + size - i);
*(a + size - i) = *(a + 127 - i);
*(a + 127 - i ) = temp;
}
return;
}
/*========================minus=======================*/
void minus(int value1[], int value2[], int result[])
{
int big;
for ( int i = 0; i < 128; i++ )
{
if ( value2[i] > value1[i] )
{
big = 2;
break;
}
if ( value1[i] > value2[i] )
{
big = 1;
break;
}
}
if ( big == 1 )
{
for ( i = 127; i >= 0 && value1[i] >= 0; i-- )
result[i] += value1[i];
for ( i = 127; i >= 0 && value2[i] >= 0; i-- )
result[i] -= value2[i];
}
if ( big == 2 )
{
for ( i = 127; i >= 0 && value2[i] >= 0; i-- )
result[i] += value2[i];
for ( i = 127; i >= 0 && value1[i] >= 0; i-- )
result[i] -= value1[i];
outtextxy(115,130,"-");
}
for ( i = 127; i >= 0; i-- )
{
if ( (result[1] / 10) + result[0] > 9 )
error();
if ( result[i] < 0 )
{
result[i] += 10;
result[i-1]--;
}
}
return;
}
/*===========================multiple=========================*/
void multiple( int value1[], int value2[], int result[] )
{
int size1 = 127, size2 = 127;
for ( int i = 127; i >= 0; i-- )
{
if ( *(value1 + i) == -1 )
{
size1 = 127 - i;
break;
}
else
continue;
}
for (i = 127; i >= 0; i-- )
{
if ( *(value2 + i) == -1 )
{
size2 = 127 - i;
break;
}
else
continue;
}
if( size1 + size2 > 129 )
error();
/* cal */
for (int j = 0; j < size2; j++)
{
for( i = 0; i < size1; i++)
*(result + 127 - i - j) += *(value1 + 127 - i ) * *(value2 + 127 - j);
}
for ( i = 127; i >= 0; i-- )
{
if ( (result[1] / 10) + result[0] > 9 )
error();
if ( result[i] > 9 )
{
result[i-1] += result[i] / 10;
result[i] %= 10;
}
}
}
/*=========== animate============*/
void animate( char ch )
{
const int x[12] = {220,255,290,220,255,290,220,255,290,340,340,340};
const int y[12] = {165,165,165,200,200,200,235,235,235,165,200,235};
char* cc;
int k;
cc[0] = ch;
cc[1] = '\0';
if ( ch == '*' ) cc[0] = 'x';
switch(ch)
{
case '1' :
case '2' :
case '3' :
case '4' :
case '5' :
case '6' :
case '7' :
case '8' :
case '9' :
k = int(ch) - 49;
break;
case '+' :
k = 9;
break;
case '-' :
k = 10;
break;
case '*' :
k = 11;
break;
default : return;
}
setfillstyle(SOLID_FILL,LIGHTBLUE);
bar(x[k], y[k] - 5, x[k] + 30, y[k] + 25);
setfillstyle(SOLID_FILL,BLUE);
bar(x[k] + 3, y[k] - 2, x[k] + 28, y[k] + 23);
delay(50);
setfillstyle(SOLID_FILL,LIGHTBLUE);
bar(x[k], y[k] - 5, x[k] + 30, y[k] + 25);
setfillstyle(SOLID_FILL,BLUE);
setcolor(BLUE);
bar3d(x[k], y[k], x[k] + 25, y[k] + 25,3,1);
setcolor(WHITE);
outtextxy(x[k] + 10, y[k] + 7,cc);
setcolor(BLUE);
}
/*======= well come ==========*/
void wellcome ( void )
{
cout<<"\n\n\n";
cout<<"\t\tWELCOME TO THE 128 DIGITS CACLULATER "<<endl;
cout<<"\n\n\n\n";
cout<<"FEW POINTS TO USE THIS CALCULATER. "<<endl<<endl;
cout<<"\n1. FIRST YOU NEED TO ENTER AN INTEGERS, THE OPERATOR THEN SECOND INTEGER. "<<endl;
cout<<"\n2. DO NOT ENTER CHARECTER INSTEAD OF INTEGER AS IT MAY CAUSE THE PROGRAM TO STOP RESPONDING."<<endl;
cout<<"\n3. TO CLEAR THE CALCULATOR AND USE AGAIN PRESS ESC"<<endl;
cout<<"\n4. TO EXIT THE PROGRAM PRESS X "<<endl<<endl;
cout<<"\n\n\n\n\n\t\t\twrite by: hossein azarpevand ";
sleep(7);
cleardevice();
}
/*========Error===================*/
void error( void )
{
setcolor(RED);
outtextxy(125,130,"Error.Result is out of range");
getch();
exit(1);
}
-
نمایش توابع مثلثاتی به فرم aY=Sin bX
نمایش توابع مثلثاتی به فرم aY=Sin bX
کد PHP:
#include <conio.h>
#include <graphics.h>
#include <math.h>
#include <iostream.h>
#include <dos.h>
#include <stdio.h>
void mehvar();
void mos_1(int,int,int);
void mos_2(int,int,int);
int main()
{
char num[5];
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
for(int i=1;i<5;i++)
for(int j=1;j<5;j++)
for(int k=1;k<5;k++)
{
mos_1(i,j,-k);
delay(1000);
nosound();
}
getch();
return 0;
}
//*******************************
void mehvar()
{
setcolor(15);
int x0,y0;
char num;
x0=getmaxx()/2;
y0=getmaxy()/2;
line(x0-300,y0+10,x0+300,y0+10);//X
line(x0,y0-200,x0,y0+200);//Y
}
//********************
void mos_1(int s,int Y,int X)
{
char num[5];
float deg,x0=320,y0=240;
clearviewport();
mehvar();
deg=-6.28;
while(deg<=6.28)
{
setcolor(14);
switch(s)
{
case 1:
outtextxy(deg*Y*40+x0,sin(deg*X)*40+y0,".");
sprintf(num,"%d",Y);
outtextxy(10,10,num);
outtextxy(20,10,"Y=Sin ");
sprintf(num,"%d",X);
outtextxy(60,10,num);
outtextxy(80,10,"X");
break;
case 2:
outtextxy(deg*Y*40+x0,cos(deg*X)*40+y0,".");
sprintf(num,"%d",Y);
outtextxy(10,10,num);
outtextxy(20,10,"Y=Cos ");
sprintf(num,"%d",X);
outtextxy(60,10,num);
outtextxy(80,10,"X");
break;
case 3:
outtextxy(deg*Y*40+x0,tan(deg*X)*40+y0,".");
sprintf(num,"%d",Y);
outtextxy(10,10,num);
outtextxy(20,10,"Y=sin ");
sprintf(num,"%d",X);
outtextxy(60,10,num);
outtextxy(80,10,"X");
break;
case 4:
outtextxy(deg*Y*40+x0,1/tan(deg*X)*40+y0,".");
sprintf(num,"%d",Y);
outtextxy(10,10,num);
outtextxy(20,10,"Y=Cot ");
sprintf(num,"%d",X);
outtextxy(60,10,num);
outtextxy(80,10,"X");
break;
}
deg+=0.01744;
}
}
-
برنامه كوله پشتي 0-1 به روش برنامه سازي پويا
برنامه كوله پشتي 0-1 به روش برنامه سازي پويا
کد PHP:
#include <iostream.h>
#include <conio.h>
void main()
{
int i,j,n,l,p[10][20];
int weight,w[10];p[10];
cout<<"enter your namber of objects";
cin>>n;
for(i=0;i {
cout<<"enter w"<<"";
cin>>w[i];
cout<<"enter p";
cin>>p[i][0];
}
for(i=0;i p[i][0]=0;
for(j=0;j p[0][j]=0;
for(i=1;i for(j=1;j {
if(w[i]<=j)
{
if(p[i-1][j] < p[i][j]+p[i-1][j-w[i]])
p[i][j]=p[i-1][j-w[i]];
else
p[i][j]=p[i][j]+p[i-1][j-w[i]];
}
else
p[i][j]=p[i-1][j];
cout<< p[i][j];
}
getch();
}
-
برنامه ی پازل به صورت برنامه نویسی back tracking یا همون(برنامه نویسی عقب گرد )
برنامه ی پازل به صورت برنامه نویسی back tracking یا همون(برنامه نویسی عقب گرد )
کد PHP:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
// N should be >= 3
#define N 4
int board[N][N];
int showBoard() {
int i,val;
int row,col;
for ( row=0; row<N ; row++)
{
for ( col=0; col<N; col++)
{
if (board[row][col] == N*N){
printf(" *");
}
else {
printf("% 4d", board[row][col]);
}
}
printf("\n");
}
return 0;
}
int findKey(int val, int *v_f, int *v_c) {
int row,col;
*v_f = 0;
*v_c = 0;
if (val >= (N*N))
{
return 1;
}
for ( row=0; row<N ; row++)
{
for ( col=0; col<N; col++)
{
if (board[row][col] == val){
*v_f = row + 1;
*v_c = col + 1;
return 0;
}
}
}
return 1;
}
int findEmpty(int *v_f, int *v_c) {
int row,col;
*v_f = 0;
*v_c = 0;
for ( row=0; row<N ; row++)
{
for ( col=0; col<N; col++)
{
if (board[row][col] == N*N){
*v_f = row + 1;
*v_c = col + 1;
return 0;
}
}
}
return 1;
}
int move(int val) {
int row,col,filv,colv;
int i;
i=findKey(val, &row, &col);
i=findEmpty(&filv, &colv);
if ((row + 1 == filv && col == colv) ||
(row - 1 == filv && col == colv) ||
(row == filv && col + 1 == colv) ||
(row == filv && col - 1 == colv) )
{
board[row - 1][col - 1] = N*N;
board[filv - 1][colv - 1] = val;
return 0;
}
return 1;
}
int loadOrderedBoard() {
int row,col;
srand( (unsigned)time( NULL ) );
for ( row=0; row<N ; row++)
{
for ( col=0; col<N; col++)
{
board[row][col] = row * N + col;
}
}
return 0;
}
int gameOver() {
int row,col;
for ( row=0; row<N ; row++)
{
for ( col=0; col<N; col++)
{
if (board[row][col] != row * N + col + 1)
{
return 1;
}
}
}
return 0;
}
int checkParity() {
int i,j,paridad,dato;
paridad = 0;
for (i=0; i<(N*N) -1; i++)
{
dato = board[i/N][i%N];
if (dato != 16)
{
for (j=i+1; j<(N*N); j++)
{
if (board[j/N][j%N] < dato )
{
paridad++;
}
}
}
else {
paridad += (i/N) + 1;
}
}
return paridad % 2;
}
int fixParity()
{
int buf;
if (board[0][0] != (N*N) && board[0][1] != (N*N))
{
buf = board[0][0];
board[0][0] = board[0][1];
board[0][1] = buf;
}
else {
buf = board[1][0];
board[1][0] = board[1][1];
board[1][1] = buf;
}
}
int cheat()
{
int buf;
buf = board[N-1][N-2];
board[N-1][N-2] = board[N-1][N-3];
board[N-1][N-3] = buf;
return 0;
}
int loadBoard()
{
int i,j;
int base[N][N];
for (i=0; i<N*N; i++)
{
base[i/N][i%N] = 0;
}
srand((unsigned)time(NULL));
i=0;
while (i < N*N)
{
j = (int) ((float) (N*N) * rand() / (RAND_MAX + 1.0));
if (base[j/N][j%N] == 0)
{
base[j/N][j%N] = j+1;
board[i/N][i%N] = j+1;
i++;
}
}
}
int main()
{
int i, moves, option, play;
printf("1- Load random Board\n");
printf("2- Load ordered Board\n");
scanf("%d", &option);
switch (option)
{
case 1: loadBoard();
break;
case 2: loadOrderedBoard();
break;
default:
printf("I don't get that option!\n");
return 0;
break;
}
showBoard();
if (checkParity() != 0)
{
printf("ODD parity - No solution Board!\n");
printf("1- Fix Parity\n");
printf("2- Leave it\n");
scanf("%d", &option);
switch (option)
{
case 1: fixParity();
break;
case 2:
break;
default:
printf("I don't get that option!\n");
return 0;
break;
}
showBoard();
}
moves = 0;
play = 0;
do
{
printf("1 - %d to move\n", N*N-1);
printf("0 to exit\n");
printf("%d to cheat\n", N*N);
printf("Option: ");
scanf("%d", &play);
if (play == N*N)
{
cheat();
}
else if (move(play) == 0)
{
moves ++;
};
showBoard();
if (gameOver() == 0)
{
printf("GAME COMPLETED IN %03d MOVES!\n", moves);
play = 0;
}
printf("\n");
}while (play != 0);
}
-
برنامه کتابخانه
برنامه کتابخانه
کد PHP:
#include <iostream>
#include <conio>
#include <fstream>
#include <algorithm>
#include <stdio>
#include <stdlib>
# define esc 27
#define enter 13
#define up 72
#define down 80
#define tab 9
class library
{
public:
struct book
{
char name[20];
char writer[20];
char date[15];
char publisher[20];
char subject[20];
int id,price;
}book1,booktemp;
int menu();
char addmenu(int *,char *);
void add();
void searchmenu(int *,char *);
void search();
void show(int*,char*,char *);
void deletmenu(char *);
void delet();
}book;
//***********************main***************************************************
int main()
{
while(1)
{
window(1,1,80,25);
textbackground(0);
textcolor(15);
clrscr();
gotoxy(29,3);
cprintf("WELCOM TO MY LIBRARY");
gotoxy(55,23);
cprintf("*** SPRING OF 1387 **");
int select=book.menu();
switch(select)
{
case 1:book.add();break;
case 2:book.search();break;
case 3:book.delet();
case 4:
cout<<"\a";
window(10,5,70,20);
textbackground(1);
textcolor(15);
clrscr();
gotoxy(15,7);
cprintf("ARE YOU SURE (y/n)?");
char ex=getch();
if(ex==13||ex==121||ex==89)
return 0;
}
}
return 0;
}
//******************************functions***************************************
int library::menu()
{
char item[4][20]={
"1->Insert","2->Search","3->Delet","4->Exit"},key;
int i=0,j=0;
window(10,5,70,20);
textbackground(3);
clrscr();
window(1,1,25,80);
while(1)
{
for(i=0;i<4;i++)
{
textbackground(3);
textcolor(14);
if(i==j)
{
textbackground(1);
textcolor(15);
}
gotoxy(2,2+(2*i));
cprintf("%s",item[i]);
}
gotoxy(2,2+(2*j));
key=getch();
switch(key)
{
case 49:j=0;break;
case 50:j=1;break;
case 51:j=2;break;
case 52:j=3;break;
case up:if(j==0)j=3;else j--;break;
case down:if(j==3)j=0;else j++;break;
case tab:if(j==3)j=0;else j++;break;
case enter:break;
case esc:return 4;
}
if(key==13)break;
}
return j+1;
}
//*****************************************
char library::addmenu(int *j,char *key)
{
char add[7][20]={
"Name :","Writer :","Date publisher :","Price :","publisher :","Subject :","Code:"};
int i,flag=0;
window(21,5,50,20);
textbackground(1);
clrscr();
while(1)
{
for(i=0;i<7;i++)
{
textbackground(1);
textcolor(14);
if(i==*j)
{
textbackground(3);
textcolor(15);
}
gotoxy(2,2+(2*i));
cprintf("%s",add[i]);
}
gotoxy(2,2+(2*(*j)));
*key=getch();
switch(*key)
{
case up:if(*j==0)*j=6;else (*j)--;break;
case down:if(*j==6)*j=0;else (*j)++;break;
case tab:if(*j==6)*j=0;else (*j)++;break;
case enter:break;
case esc:break;
}
if(*key==13||*key==27)break;
}
}
//****************************************************
void library::add()
{
char add[7][20]={
"Name :","Writer :","Date publisher :","Price :","publisher :","Subject :","Code:"},key;
int j=0;
char ch=addmenu(&j,&key);
ofstream file1("C:\\library.dat",ios::app);
if(!file1) cout<<"\ncan not open file";
if(ch==13)
{
gotoxy(2,2+(2*j));textbackground(1);textcolor(14);cprintf("%s",add[j]);
gotoxy(2,2);textbackground(3);textcolor(15);cprintf("%s",add[0]);
gotoxy(8,2);cin.get(book1.name,20);cin.get();
gotoxy(10,4);cin.get(book1.writer,20);cin.get();
gotoxy(18,6);cin.get(book1.date,20);cin.get();
gotoxy(9,8);cin>>book1.price;cin.get();
gotoxy(13,10);cin.get(book1.publisher,20);cin.get();
gotoxy(11,12);cin.get(book1.subject,20);cin.get();
gotoxy(7,14);cin>>book1.id;cin.get();
file1.write((char*)&book1,sizeof(struct book));
file1.close();
}
}
//********************************************************
void library::searchmenu(int*j,char*key)
{
char add[3][20]={"Name :","subject :","Code:"};
int i,flag=0;
window(21,7,50,15);
textbackground(1);
clrscr();
while(1)
{
for(i=0;i<3;i++)
{
textbackground(1);
textcolor(14);
if(i==*j)
{
textbackground(3);
textcolor(15);
}
gotoxy(2,2+(2*i));
cprintf("%s",add[i]);
}
gotoxy(2,2+(2*(*j)));
*key=getch();
switch(*key)
{
case up:if(*j==0)*j=2;else (*j)--;break;
case down:if(*j==2)*j=0;else (*j)++;break;
case tab:if(*j==2)*j=0;else (*j)++;break;
case enter:break;
case esc:break;
}
if(*key==13||*key==27)break;
}
}
//*************************************************************
void library::search ()
{
char add[3][20]={"Name :","subject :","Code:"},ch,n[20];
int i,j,cod;
searchmenu(&j,&ch);
if(ch!=27)
{
switch(j)
{
case 0:gotoxy(8,2);cin.get(n,20);cin.get();i=1;break;
case 1:gotoxy(11,4);cin.get(n,20);cin.get();i=2;break;
case 2:gotoxy(7,6);cin.get(n,20);cin.get();i=3;break;
}
}
int x=atol(n);
show(&x,n,&ch);
}
//*************************************************************
void library::show(int *x,char*n,char *ch)
{
char item[7][20]={
"Name :",
"Writer :",
"Date publisher :",
"Price :",
"publisher :",
"Subject :",
"Code:"
};
if(*ch!=27)
{
ifstream file1("C:\\library.dat",ios::out);
if(!file1) cout<<"\ncan not open file";
int j=0;
if((*x)>0) while(file1.read((char*)&book1,sizeof(struct book)))
if(*x==book1.id)
{
j=1;
booktemp=book1;
break;
}
if(*x==0) while(file1.read((char*)&book1,sizeof(struct book)))
if(strcmp(book1.name,n)==0||strcmp(book1.subject,n)==0)
{
j=1;
booktemp=book1;
break;
}
file1.close();
window(10,5,70,20);
textbackground(6);
clrscr();
if(j==0)
{
textcolor(1);
gotoxy(6,7);
cprintf("!!! NOT FOUND THIS BOOK IN THE LIBRARY !!!");
gotoxy(15,10);
cprintf("PRESS ANY KEY TO COMTINUE :");
}
else
{
for(int i=0;i<7;i++)
{
textcolor(1);
gotoxy(2,(i+1)*2);
cprintf("%s",item[i]);
}
gotoxy(8,2);cprintf("%s",book1.name);
gotoxy(10,4);cprintf("%s",book1.writer);
gotoxy(18,6);cprintf("%s",book1.date);
gotoxy(9,8);cout<<book1.price;
gotoxy(13,10);cprintf("%s",book1.publisher);
gotoxy(11,12);cprintf("%s",book1.subject);
gotoxy(7,14);cout<<book1.id;
}
getch();
}
}
//**********************************************
void library::deletmenu(char *key)
{
window(20,9,35,11);
textbackground(1);
textcolor(14);
clrscr();
textcolor(15);
textbackground(3);
gotoxy(2,2);cprintf("Book code :");
gotoxy(2,2);
*key=getch();
}
//********************************
void library::delet()
{
char add[7][20]={
"Name :",
"Writer :",
"Date publisher :",
"Price :","publisher :",
"Subject :",
"Code:"};
char ch;
int code,i,f;
ofstream file2("C:\\temp.dat",ios::in);
if(!file2) cout<<"\ncan not open file";
ifstream file1("C:\\library.dat",ios::out);
if(!file1) cout<<"\ncan not open file";
deletmenu(&ch);
if(ch!=27)
{
gotoxy(13,2);
cin>>code;
}
while(file1.read((char*)&book1,sizeof(struct book)))
{
if(book1.id!=code)
file2.write((char*)&book1,sizeof(struct book));
if(book1.id==code)
{
window(10,5,70,22);
textbackground(1);
textcolor(15);
clrscr();
gotoxy(10,2);cprintf("PLEASE ENTER NEW INFORMATION OF BOOK");cin.get();
gotoxy(2,4);cprintf("%s",add[0]);cin.get(booktemp.name,20);cin.get();
gotoxy(2,6);cprintf("%s",add[1]);cin.get(booktemp.writer,20);cin.get();
gotoxy(2,8);cprintf("%s",add[2]);cin.get(booktemp.date,20);cin.get();
gotoxy(2,10);cprintf("%s",add[3]);cin>>booktemp.price;cin.get();
gotoxy(2,12);cprintf("%s",add[4]);cin.get(booktemp.publisher,20);cin.get();
gotoxy(2,14);cprintf("%s",add[5]);cin.get(booktemp.subject,20);cin.get();
gotoxy(2,16);cprintf("%s",add[6]);cin>>booktemp.id;cin.get();
file2.write((char*)&booktemp,sizeof(struct book));
}
}//end of while
file1.close();
file2.close();
remove("C:\\library.dat");
rename("C:\\temp.dat","C:\\library.dat");
}
-
دریافت و چاپ گراف
دریافت و چاپ گراف
کد PHP:
#include <iostream>
#include <conio>
void print(int[][100],int);
void p();
int v,i,j,e[100][100];
char ch;
int main()
{
p();
cout<<"\n\nPlease enter the number of V:";
cin>>v;
while(1)
{
clrscr();
p();
cout<<"\n\nWhat do you want to do?\n\n";
cout<<"1-Insert a new Yal\n2-Delete a Yal\n3-Print Graph\n4-Exit\n\n";
cout<<"What is Your selection:";
cin>>ch;
switch(ch)
{
case'1':
clrscr();
p();
cout<<"\n\nplease enter Yal:";
cin>>i>>j;
if(i>v||j>v)
{
cout<<"\n\nWarning!!! you must enter two number betwen 0-"<<v;
getch();
}
else
e[i][j]=1;
break;
case'2':
clrscr();
p();
print(e,v);
cout<<"\n\nplease enter your Deleted Yal:";
cin>>i>>j;
e[i][j]=0;
break;
case'3':
print(e,v);
getch();
break;
case'4':return 0;
}
}
getch();
return 0;
}
//*********************************************************
void print(int graph[][100],int v)
{
int i,j;
clrscr();
p();
cout<<"\n";
for(i=0;i<v;i++)
{
cout<<i<<" ";
for(j=0;j<v;j++)
{
cout<<graph[i][j]<<" ";
}
cout<<"\n";
}
cout<<"\n ";
for(i=0;i<v;i++)
cout<<i<<" ";
cout<<"\n\nV(G)={";
for(i=0;i<v;i++)
{
cout<<i;
if(i<v-1)
cout<<",";
}
cout<<"}";
cout<<"\n\nE(G)={";
for(i=0;i<v;i++)
{
for(j=0;j<v;j++)
{
if(graph[i][j]==1)
cout<<"("<<i<<","<<j<<")";
}
}
cout<<"}";
}
//*********************************************************
void p()
{
gotoxy(55,23);
cout<<"*** Writing By Hossein ***";
gotoxy(1,1);
}