mnf777
سه شنبه 03 تیر 1393, 03:15 صبح
سلام به همه دوستان خوبم@};-
ما باید یه برنامه مینوشتیم که ی عبارت ریاضیو از کاربر بگیره خب؟ بعد عرض کنم که درختشو رسم کنه اول بعد فرم پیشوندیو پسوندیشم حساب کنه؟
تا اینجا پیش رفتیم با علی ولی برنامه هییی ارور میده تو قسمت "سوییچ کیس 2او3" موندیم خدایی! از دوستان کسی هس بتونه کمک کنه؟ ممنون میشیم;-)
ارورشم اینه" Error 1 error C2360: initialization of 'c' is skipped by 'case' label
Error 2 error C2360: initialization of 'c' is skipped by 'case' label
// Poroje of payan term.cpp : Defines the entry point for the console application.//
#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <string.h>
using namespace std;
class node{
public:
char value [11];
node *child_left;
node *child_right;
};
node *reshe = NULL;
void insert (node *c)
{
node *a;
node *b;
b = NULL;
a = reshe;
while ( a!=NULL)
{
b = a;
if(strcmp(c->value,a->value) < 0)
{
a= a-> child_left;
}
else
{
a= a-> child_right;
}
}
if( b==NULL )
{
reshe=c;
}
else if(strcmp( c->value,b->value) < 0)
{
b -> child_left = c;
}
else
{
b-> child_right = c;
}
}
void preorder( node *r )
{
cout<< r -> value << " ";
if (r->child_left != NULL)
preorder (r->child_left);
if (r->child_right != NULL)
preorder (r->child_right);
}
void inorder( node *r )
{
if (r->child_left != NULL)
inorder (r->child_left);
cout<< r -> value << " ";
if (r->child_right != NULL)
inorder (r->child_right);
}
void postorder( node *r )
{
if (r->child_left != NULL)
postorder (r->child_left);
if (r->child_right != NULL)
postorder (r->child_right);
cout<< r -> value << " ";
}
void main()
{
int choice;
while (choice!=3){
system("cls");
cout<<"\n\n\t 1. Insert a Expression.";
cout<<"\n\n\t 2. peymayesh.";
cout<<"\n\n\t 3. Exit.";
cout<<"\n\n\t Enter your choice : ";
cin>>choice;
switch (choice)
{
case 1: system("cls");
node *c=new node;
cout<<"\n\n\t Enter your Expression Trees: ";
cin >> c->value;
c->child_right=NULL;
c->child_left=NULL;
insert(c);
break;
case 2: system("cls");
cout << "\n\n\t peymayesh Preorder : ";
preorder(reshe);
cout << "\n\n\t peymayesh Inorder : ";
inorder(reshe);
cout << "\n\n\t peymayesh Postorder : ";
postorder(reshe);
getchar();
getchar();
break;
case 3: break;
}
}
}
ما باید یه برنامه مینوشتیم که ی عبارت ریاضیو از کاربر بگیره خب؟ بعد عرض کنم که درختشو رسم کنه اول بعد فرم پیشوندیو پسوندیشم حساب کنه؟
تا اینجا پیش رفتیم با علی ولی برنامه هییی ارور میده تو قسمت "سوییچ کیس 2او3" موندیم خدایی! از دوستان کسی هس بتونه کمک کنه؟ ممنون میشیم;-)
ارورشم اینه" Error 1 error C2360: initialization of 'c' is skipped by 'case' label
Error 2 error C2360: initialization of 'c' is skipped by 'case' label
// Poroje of payan term.cpp : Defines the entry point for the console application.//
#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <string.h>
using namespace std;
class node{
public:
char value [11];
node *child_left;
node *child_right;
};
node *reshe = NULL;
void insert (node *c)
{
node *a;
node *b;
b = NULL;
a = reshe;
while ( a!=NULL)
{
b = a;
if(strcmp(c->value,a->value) < 0)
{
a= a-> child_left;
}
else
{
a= a-> child_right;
}
}
if( b==NULL )
{
reshe=c;
}
else if(strcmp( c->value,b->value) < 0)
{
b -> child_left = c;
}
else
{
b-> child_right = c;
}
}
void preorder( node *r )
{
cout<< r -> value << " ";
if (r->child_left != NULL)
preorder (r->child_left);
if (r->child_right != NULL)
preorder (r->child_right);
}
void inorder( node *r )
{
if (r->child_left != NULL)
inorder (r->child_left);
cout<< r -> value << " ";
if (r->child_right != NULL)
inorder (r->child_right);
}
void postorder( node *r )
{
if (r->child_left != NULL)
postorder (r->child_left);
if (r->child_right != NULL)
postorder (r->child_right);
cout<< r -> value << " ";
}
void main()
{
int choice;
while (choice!=3){
system("cls");
cout<<"\n\n\t 1. Insert a Expression.";
cout<<"\n\n\t 2. peymayesh.";
cout<<"\n\n\t 3. Exit.";
cout<<"\n\n\t Enter your choice : ";
cin>>choice;
switch (choice)
{
case 1: system("cls");
node *c=new node;
cout<<"\n\n\t Enter your Expression Trees: ";
cin >> c->value;
c->child_right=NULL;
c->child_left=NULL;
insert(c);
break;
case 2: system("cls");
cout << "\n\n\t peymayesh Preorder : ";
preorder(reshe);
cout << "\n\n\t peymayesh Inorder : ";
inorder(reshe);
cout << "\n\n\t peymayesh Postorder : ";
postorder(reshe);
getchar();
getchar();
break;
case 3: break;
}
}
}