#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <iostream>
#include <string.h>
using namespace std;
void main ()
{
int w;
int n,i;
int day,m1,m2,year,dd;
//printf("Insert n:");
cout<<"\tShanbe=0\t1shanbe=1\t2shanbe=2\t3shanbe=3 \t4shanbe=4\t5shanbe=5\tjomee=6\n";
do{
cout<<"Insert First Day (#<7) :";
cin>>n;
}while (n>7);
do{
cout<<"Insert year (1300< (####) <1900) :";
cin>>year;
}while (year<1300);
i=0; day=1; m1=1; m2=1;
char str[12][15]={"farvardin\n","ordibehesht\n","khordad\n","tir\n ","mordad\n","shahrivar\n","mehr\n","aban\n","azar \n","dey\n","bahman\n","esfand\n"};
cout<<"\tShanbe\t1shanbe\t2shanbe\t3shanbe\t4shanb e\t5shanbe\tjomee\n";
cout<<str[0];
while (m1 <=6)
{
while(day<32)
{
for (int j=0;j<n;j++)
cout<<"\t";
for (i=n;i<7 && day<32;i++)
{
cout<<"\t"<<day;
day++;
w=i;
}
cout<<"\n";
n=0;
}
cout<<"\n \n";
cout<<str[m1];
i=0;
day=1;
n=w+1;
m1++;
}
while (m2 <6)
{
while(day<31)
{
for (int j=0;j<n;j++)
cout<<"\t";
for (i=n;i<7 && day<31;i++)
{
cout<<"\t"<<day;
day++;
w=i;
}
cout<<"\n";
n=0;
}
cout<<"\n \n";
cout<<str[m1+m2-1];
i=0;
day=1;
n=w+1;
m2++;
}
if(year%4==3)
dd=31;
else dd=30;
while(day<dd)
{
for (int j=0;j<n;j++)
cout<<"\t";
for (i=n;i<7 && day<dd;i++)
{
cout<<"\t"<<day;
day++;
w=i;
}
cout<<"\n";
n=0;
}
//cin>>n;
getch();
}
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <iostream.h>
#include <string.h>
//using namespace std;
void main ()
{
int w;
int n,i;
int day,m1,m2,year,dd;
//printf("Insert n:");
cout<<"\tShanbe=0\t1shanbe=1\t2shanbe=2\t3shanbe=3 \t4shanbe=4\t5shanbe=5\tjomee=6\n";
do{
cout<<"Insert First Day (#<7) :";
cin>>n;
}while (n>7);
do{
cout<<"Insert year (1300< (####) <1900) :";
cin>>year;
}while (year<1300);
i=0; day=1; m1=1; m2=1;
char str[12][15]={"farvardin\n","ordibehesht\n","khordad\n","tir\n ","mordad\n","shahrivar\n","mehr\n","aban\n","azar \n","dey\n","bahman\n","esfand\n"};
cout<<"\tShanbe\t1shanbe\t2shanbe\t3shanbe\t4shanb e\t5shanbe\tjomee\n";
cout<<str[0];
while (m1 <=6)
{
while(day<32)
{
for (int j=0;j<n;j++)
cout<<"\t";
for (i=n;i<7 && day<32;i++)
{
cout<<"\t"<<day;
day++;
w=i;
}
cout<<"\n";
n=0;
}
cout<<"\n \n";
cout<<str[m1];
i=0;
day=1;
n=w+1;
m1++;
}
while (m2 <6)
{
while(day<31)
{
for (int j=0;j<n;j++)
cout<<"\t";
for (i=n;i<7 && day<31;i++)
{
cout<<"\t"<<day;
day++;
w=i;
}
cout<<"\n";
n=0;
}
cout<<"\n \n";
cout<<str[m1+m2-1];
i=0;
day=1;
n=w+1;
m2++;
}
if(year%4==3)
dd=31;
else dd=30;
while(day<dd)
{
for (int j=0;j<n;j++)
cout<<"\t";
for (i=n;i<7 && day<dd;i++)
{
cout<<"\t"<<day;
day++;
w=i;
}
cout<<"\n";
n=0;
}
//cin>>n;
getch();
}
daghighan manzooreto nafahmidam vali age neveshte haye ghablet pak nemishe bayad bad az DO , clrscr() bezari
age javabe ghablit ham hamrahe in chap mishe bayad araye A ke tarif kardi ebtedaye halghe Do while tamame anasoresh ro barabare 0 bedi ta meghdarhaye ghabli azash pak she.
for(int i=0;i<n;i++)
A=0;
سلام دوست عزیز
این دستور که شما نوشتی یک حلقه بی پایان درست میکنه.
while(1) halhje bi nahayate
vase zakhire char va int dakhele yek araye bayad adadi ke zakhire mishe be char tabdil beshe va vaghty az araye avordi biroon age meghdare adadi ro khasty bayad be adad tabdilesh koni
tabdile char be adad : atoi(char)
tabdile adad be char : itoa(int)
سلام و عرض تشكر از اينكه با حوصله جواب مي دهيد دوست عزيز يعني من مي توانم چنين بنويسم switch(n%16) { case 10: A='A'; break; case 11: A='B'; break; case 12: A='C'; break; case 13: A='D'; break; case 14: A='E'; break; case 15: A='F'; break; default: A=itoa(n%16); }
fek konam mikhay halate defaultet adad ro berizi too array ke bayad haminjoori benvisi
daghighan mikhay barnamat chikar kone ?
برنامه درخت جستجوی دودویی (binary search tree). با استفاده از کلاس ها.
Binary Search Tree
#include<iostream.h>
#include<conio.h>
#include<alloc.h>
struct tree
{
int data;
tree *left;
tree *right;
}*sptr,*q;
void rightcheck();
void leftcheck();
void search();
int insdata;
tree *node;
void main()
{
clrscr();
node=new tree;
cout<<" PLEASE PUT THE root->>";
cin>>node->data;
sptr=node;
q=sptr;
node->left=NULL;
node->right=NULL;
cout<<" GIVE THE child->>";
cin>>insdata;
search();
while(insdata!=0)
{
if(insdata>sptr->data)
rightcheck();
else
leftcheck();
cout<<" GIVE THE child->>";
cin>>insdata;
search();
sptr=node;
}
getch();
}
void rightcheck()
{
if(sptr->right==NULL)
{
cout<<" "<<insdata<<" IS THE RIGHT child of "<<q->data<<endl;
sptr->right=new tree;
sptr=sptr->right;
sptr->data=insdata;
sptr->left=NULL;
sptr->right=NULL;
q=node;
}
else
{
if(insdata>sptr->data)
{
sptr=sptr->right;
q=sptr;
if(insdata>sptr->data)
rightcheck();
else
leftcheck();
}
else
{
sptr=sptr->left;
q=sptr;
leftcheck();
}
}
}
void leftcheck()
{
if(sptr->left==NULL)
{
cout<<" "<<insdata<<" IS THE LEFT child of "<<q->data<<endl;
sptr->left=new tree;
sptr=sptr->left;
sptr->data=insdata;
sptr->right=NULL;
sptr->left=NULL;
q=node;
}
else{
if(insdata<sptr->data)
{
sptr=sptr->left;
q=sptr;
if(insdata>sptr->data)
rightcheck();
else
leftcheck();
}
else
{
sptr=sptr->right;
q=sptr;
rightcheck();}
}
}
void search()
{
sptr=node;
while(sptr!=NULL)
{
if(insdata==sptr->data)
{
cout<<"This is not insertable.";
cout<<"\nInsert child ";
cin>>insdata;
search();
break;
}
else
{
if(insdata>sptr->data)
sptr=sptr->right;
else
sptr=sptr->left;
}
}
sptr=node;
}
[/LEFT]
باشه اميد جان
حميد و اميد!عجب تفاهمي!
حالا نمي شه به جاي ازدواج همكار بشيم؟
نعععععععععع!سلام.سال بلايي هاي عزيز شما كه اين برنامه هاي سخت سخت رو نوشتين يه برنامه ي binary search tree براي من بنويسين لطفا.ممنون.
//TO WRITE A PROGRAM TO SEARCH FOR A GIVEN ELEMENT FROM AN ARRAY USING BINARY
//SEARCH TECHNIQUE
#include<iostream.h>
#include<conio.h>
void binsearch(int ar[],int size,int ele)
{ int lb=0,ub=size-1,mid; //lb=>lower bound,ub=>upper bound
for(;lb<ub;)
{
mid=(lb+ub)/2;
if(ar[mid]==ele)
{
cout<<"\n SEARCH SUCCESSFUL";
break;
}
else
if(ar[mid]<ele)
ub=mid-1;
else
if(ar[mid]>ele)
lb=mid+1;
}
if(ub<lb)
cout<<"\n SEARCH UNSUCCESSFUL";
}
void sort(int ar[],int size) //sorts the array in ascending array using bubble sort
{
int temp;
for(int i=0;i<size;i++)
for(int j=0;j<size-i-1;j++)
if(ar[j]>ar[j+1])
{
temp=ar[j];
ar[j]=ar[j+1];
ar[j+1]=temp;
}
}
void display(int ar[],int size)
{
for(int i=0;i<size;i++)
cout<<'\n'<<ar[i];
}
void input(int ar[],int size)
{
for(int i=0;i<size;i++)
cin>>ar[i];
}
void main()
{
clrscr();
int size;
cout<<"\n ENTER THE NUMBER OF ELEMENTS REQUIRED IN THE ARRAY :";
cin>>size;
int *ar=new int(size);
cout<<"\n ENTER THE ELEMENTS OF THE ARRAY :\n";
input(ar,size); //takes the input from the array
sort(ar,size); //sorts the array in the ascending order
int ele;
cout<<"\n ENTER THE ELEMENT TO BE FOUND :\n";
cin>>ele;
getch();
}
[FONT=Courier New][SIZE=2]#include <iostream.h>
int BinarySearch(int [], int, int);
int [B]main[/B]()
{[/SIZE][/FONT] [FONT=Courier New][SIZE=2]
const int NUMEL = 10;
int nums[NUMEL] = {5,10,22,32,45,67,73,98,99,101};
int item, location;
cout << "Enter the item you are searching for: ";
cin >> item;
[B]location = BinarySearch(nums, NUMEL, item);[/B]
if (location > -1)
cout << "The item was found at index location "
<< location << endl;
else
cout << "The item was not found in the list\n";
return 0;
}
// this function returns the location of key in the list
// a -1 is returned if the value is not found
[/SIZE][/FONT] [FONT=Courier New][SIZE=2]int [B]BinarySearch[/B](int list[], int size, int key)
[/SIZE][/FONT] [FONT=Courier New][SIZE=2]{
int left, right, midpt;
left = 0;
right = size - 1;
while (left <= right)
{
midpt = (int) ((left + right) / 2);
if (key == list[midpt])
{
[B]return[/B] midpt;
}[/SIZE][/FONT] [FONT=Courier New][SIZE=2]
else if (key > list[midpt])
left = midpt + 1;
else
right = midpt - 1;
}
[B]return [/B]-1;
}[/SIZE][/FONT]
دوست عزيز بايستي برنامه اي براي تبديل دسيمال به هگزا و برعكس بنويسم چون در مبناي هگزا از حروف استفاده مي شود بنابراين اگر آرايه از نوع int تعريف شود كاراكترها را نمي نويسد و اگر از نوع Char باشد اعداد را يا نمي نويسد يا اينكه بهم مي ريزد ميخواستم در بخش defaule دستور سوئيچ عدد به كاراكتر تبديل شود و داخل آرايه از نوع كاراكتر ذخيره گردد.
با تشكر