برگزیده های پرشین تولز

رفع خطاي برنامه سي++

farazzz

کاربر تازه وارد
تاریخ عضویت
7 فوریه 2004
نوشته‌ها
26
لایک‌ها
0
سلام دوستان.من یه مشکلی داشتم.ممنون میشم اگه کمکم کنید.
من تو سی ++ یه کلاس رو به شکل زیر تعریف کردم :
کد:
class teams
{
private:
   char name[20];
   int won;
   int draw;
   int lost;
   int gs;
   int ga;
   int points;
public:
   void increase_points(int z,k)
   {
   if(z>k) {won++;points+=3;}
      else if(z==k) {draw++;points+=1;}
         else {lost++;}}//end of function
   void increase_goals(int z,k)
   {
   gs+=z;
   ga+=k;}//end of function
};//end of class declaration

و بعد تو برنامه یه آرایه از اشیائ این کلاس تعریف کردم و اینطوری ازشون استفاده کردم :
کد:
   cout<<team[a].name<<" - "<<team[b].name<<" :";
   cin>>f[j].hg>>f[j].gg;
   team[a].increase_goals(f[j].hg,f[j].gg);
   team[a].increase_points(f[j].hg,f[j].gg);
   team[b].increase_goals(f[j].gg,f[j].hg);
   team[b].increase_points(f[j].gg,f[j].hg);
}

ولی موقع ران کردن این ارورها رو میده :
type name expected
increase_goals' is not a member of 'teams'
'increase_points' is not a member of' teams'

حالا نمیدونم مشکل کجاست؟(در ضمن کامپایلرم هم بورلند سی ++ 5.02 هست.ممکنه مشکل از کامپایلر باشه؟)
 

Arman_BTC

کاربر تازه وارد
تاریخ عضویت
28 فوریه 2006
نوشته‌ها
138
لایک‌ها
1
سلام
شما اسم کلاس رو teamsگزاشتید ولی در main نوشتید team و یکی دیگه اینکه در تعریف تابع
کد:
void increase_points(int z,k)
باید بنویسید
کد:
void increase_points(int z,int k)
فکر میکنم برنامتون برد و باخت تعداد گلها و امتیازات تیم ها رو محاسبه میکنه.منظورتون از team[a]ارایه است؟
 

farazzz

کاربر تازه وارد
تاریخ عضویت
7 فوریه 2004
نوشته‌ها
26
لایک‌ها
0
سلام.ممنون ایراد ها با راهنماییتون حل شد.
بله من در برنامه یک آرایه از اشیاء این کلاس تعریف کردم.
کد:
teams team[6];

حالا این ایراد رو میگیره:
teams::name is not accessible

این هم برنامه کامل (بخش پایین برنامه که بصورت کامنت هست هنوز سر جاش قرار نگرفته):
کد:
#include<iostream.h>
#include<conio.h>
/////////////////////////////////////CLASS//////////////////////////////////////
class teams
{
private:
   char name[20];
   int won;
   int draw;
   int lost;
   int gs;
   int ga;
   int points;
public:
   void increase_points(int z,int k)
   {
   if(z>k) {won++;points+=3;}
      else if(z==k) {draw++;points+=1;}
         else {lost++;}}//end of function
   void increase_goals(int z,int k)
   {
   gs+=z;
   ga+=k;}//end of function
};//end of class declaration
////////////////////////////////////STRUCTURE///////////////////////////////////
struct fixture{
   int host;
   int guest;
   int week;
   int hg;
   int gg;
};//end of structure
/////////////////////////////////////MAIN///////////////////////////////////////
void main(){
   int i,option1;
   fixture f[15];
   teams team[6];
   cout<<"This is the first page of the football league results program \n";
   cout<<"written by Azad University-North Branch students.\n";
   for(i=0;i<6;i++){
      cout<<"Please enter a Name for the team number "<<i<<" :";
      cin>>team[i].name; }//gets team names
   cout<<"entered the following teams:\n";
   for(i=0;i<6;i++)
   cout<<(i+1)<<". "<<team[i].name<<"\n";
   cout<<"Please enter the team number to correct any probable mistake.\n";
   cout<<"If it doesn't have any mistake press another key to continue.\n";
   cin>>option1;
   while (option1<7 && option1>0){
      cin>>team[option1-1].name;
      cout<<"Another mistake? Type the number:";
      cin>>option1;}
   f[0].host=1;f[0].guest=2;f[0].week=1;
   f[1].host=3;f[1].guest=4;f[1].week=1;
   f[2].host=5;f[2].guest=6;f[2].week=1;
   f[3].host=1;f[3].guest=3;f[3].week=2;
   f[4].host=2;f[4].guest=6;f[4].week=2;
   f[5].host=5;f[5].guest=4;f[5].week=2;
   f[6].host=1;f[6].guest=4;f[6].week=3;
   f[7].host=3;f[7].guest=6;f[7].week=3;
   f[8].host=2;f[8].guest=5;f[8].week=3;
   f[9].host=1;f[9].guest=5;f[9].week=4;
   f[10].host=3;f[10].guest=2;f[10].week=4;
   f[11].host=6;f[11].guest=4;f[11].week=4;
   f[12].host=1;f[12].guest=6;f[12].week=5;
   f[13].host=3;f[13].guest=5;f[13].week=5;
   f[14].host=2;f[14].guest=4;f[14].week=5;
   
   cout<<"Please enter the results for weeks 1 to 5 :\n";
for(int j=0;j<15;j++){
   int a,b;
   a=f[j].host;
   b=f[j].guest;
   cout<<team[a].name<<" - "<<team[b].name<<" :";
   cin>>f[j].hg>>f[j].gg;
   team[a].increase_goals(f[j].hg,f[j].gg);
   team[a].increase_points(f[j].hg,f[j].gg);
   team[b].increase_goals(f[j].gg,f[j].hg);
   team[b].increase_points(f[j].gg,f[j].hg);
};}

////////////////////////////SORT & VIEW TABLE///////////////////////////////////
/*
int table[6];
for(int p=0;p<6;p++)
   table[p]=p;
int temp
   for(int q=0;q<6;q++)
      for(int r=1;r<6;r++)
         if(team[r].points>team[p].points){
         temp=q;
         q=r;
         r=temp;}
         else if(team[r].points==team[p].points){
         temp=q;
         q=r;
         r=temp;}
cout<<"Team"<<setw(10)<<"Won"<<setw(4)<<"Draw"<<setw(4)<<"Lost"<<setw(4);
cout<<"GS"<<setw(4)<<"GA"<<setw(4)
for(p=0;p<6;p++){
   temp=table[p];
   cout<<team[temp].name<<setw(10)<<team[temp].won<<setw(4)<<team[temp].draw<<setw(4);
   cout<<team[temp].lost<<setw(4)<<team[temp].gs<<setw(4)<<team[temp].ga<<setw(4);}
*/


////////////////////////VIEW RESULTS PER WEEK///////////////////////////////////


/*
cout<<"Please enter the week you want to see its results:";
cin>>n; //number of week
for(int t=0;t<15;t++){
if(f[t].week=n){
int temp1,temp2;
temp1=f[t].host;
temp2=f[t]guest;
cout<<team[temp1]<<" "<<f[t].hg<<" - "<<team[temp2]<<f[t].gg;}
*/

کار برنامه هم اینه که 6 تیم رو بگیره ، بعد نتایجشون رو بگیره ، جدول مسابقات رو تشکیل بده و به تناسب درخواست کاربر نتایج هفته ها یا جدول رو بهش نشون بده.بعد هم نتایج و جدول رو تو یک فایل ذخیره کنه.
 

Arman_BTC

کاربر تازه وارد
تاریخ عضویت
28 فوریه 2006
نوشته‌ها
138
لایک‌ها
1
شما در دستور team.name;از nameاستفاده کردید که جزو اعضای خصوصی کلاسه و این اعضا فقط توسط توابع عضو کلاس قابل دسترسی هستند که پیغام خطا هم همین رو میگفت.
من در قسمت عمومی کلاس دو تابع تعریف کردم که کارشون گرفتن نام و دیگری چاپ نام هست بعد از این توابع در قسمت mainبرنامه استفاده کردم.ودر موقع استفاده از اون ها دیگه نیازی به cin وcout نیست.

کد:
class teams
{
private:
	char name[20];
	int won;
	int draw;
	int lost;
	int gs;
	int ga;
	int points;
public:
	void get(){
	cin>>name;}
	void show(){
	cout<<name;}
	void increase_points(int z,int k)
	{
	if(z>k) {won++;points+=3;}
		else if(z==k) {draw++;points+=1;}
			else {lost++;}}//end of function
	void increase_goals(int z,int k)
	{
	gs+=z;
	ga+=k;}//end of function
};//end of class declaration
////////////////////////////////////STRUCTURE///////////////////////////////////
struct fixture{
	int host;
	int guest;
	int week;
	int hg;
	int gg;
};//end of structure
/////////////////////////////////////MAIN///////////////////////////////////////
void main(){
	int i,option1;
	fixture f[15];
	teams team[6];
	cout<<"This is the first page of the football league results program \n";
	cout<<"written by Azad University-North Branch students.\n";
	for(i=0;i<6;i++){
		cout<<"Please enter a Name for the team number "<<i<<" :";
		team[i].get(); }//gets team names
	cout<<"entered the following teams:\n";
	for(i=0;i<6;i++)
	cout<<(i+1)<<". ";
	team[i].show();
	cout<<"Please enter the team number to correct any probable mistake.\n";
	cout<<"If it doesn't have any mistake press another key to continue.\n";
	cin>>option1;
	while (option1<7 && option1>0){
		team[option1-1].get();
		cout<<"Another mistake? Type the number:";
		cin>>option1;}
	f[0].host=1;f[0].guest=2;f[0].week=1;
	f[1].host=3;f[1].guest=4;f[1].week=1;
	f[2].host=5;f[2].guest=6;f[2].week=1;
	f[3].host=1;f[3].guest=3;f[3].week=2;
	f[4].host=2;f[4].guest=6;f[4].week=2;
	f[5].host=5;f[5].guest=4;f[5].week=2;
	f[6].host=1;f[6].guest=4;f[6].week=3;
	f[7].host=3;f[7].guest=6;f[7].week=3;
	f[8].host=2;f[8].guest=5;f[8].week=3;
	f[9].host=1;f[9].guest=5;f[9].week=4;
	f[10].host=3;f[10].guest=2;f[10].week=4;
	f[11].host=6;f[11].guest=4;f[11].week=4;
	f[12].host=1;f[12].guest=6;f[12].week=5;
	f[13].host=3;f[13].guest=5;f[13].week=5;
	f[14].host=2;f[14].guest=4;f[14].week=5;

	cout<<"Please enter the results for weeks 1 to 5 :\n";
for(int j=0;j<15;j++){
	int a,b;
	a=f[j].host;
	b=f[j].guest;
	team[a].show();
	cout<<" - ";
	team[b].show();
	cout<<" :";
	cin>>f[j].hg>>f[j].gg;
	team[a].increase_goals(f[j].hg,f[j].gg);
	team[a].increase_points(f[j].hg,f[j].gg);
	team[b].increase_goals(f[j].gg,f[j].hg);
	team[b].increase_points(f[j].gg,f[j].hg);
};}


*/
 

farazzz

کاربر تازه وارد
تاریخ عضویت
7 فوریه 2004
نوشته‌ها
26
لایک‌ها
0
واقعا ممنون.خیلی لطف کردین
اگه باز هم مشکلی داشتم می پرسم.باز هم خیلی ممنون:blush: :blush:
 

Arman_BTC

کاربر تازه وارد
تاریخ عضویت
28 فوریه 2006
نوشته‌ها
138
لایک‌ها
1
خواهش میکنم;)
 

farazzz

کاربر تازه وارد
تاریخ عضویت
7 فوریه 2004
نوشته‌ها
26
لایک‌ها
0
آقا شرمنده:blush: یه مشکل دیگه:
HTML:
case 2:{
int n;
cout<<"Please enter the week you want to see its results:";
cin>>n; //number of week
for(int t=0;t<15;t++){
if(f[t].week==n){
int temp1,temp2;
temp1=f[t].host;
temp2=f[t].guest;
team[temp1].show();
cout<<" "<<f[t].hg<<" - " ;
cout<<f[t].gg<<" ";
team[temp2].show();
cout<<endl;};};}

برای کیس 2 این ارور رو میده :
case bypasses initialization of a local variable

در صورتی که وقتی کیس 1 نبود این ارور رو نمی داد و برنامه درست اجرا می شد.

HTML:
case 1:{
int table[6],p,q,r;
for(p=0;p<6;p++)
   table[p]=p;
int temp;
   for(q=0;q<6;q++)
      for(int r=1;r<6;r++)
         if(team[r].point()>team[p].point()){
         temp=q;
         q=r;
         r=temp;}
         else if(team[r].point()==team[p].point())
            if(team[r].avr()>team[p].avr()){
         temp=q;
         q=r;
         r=temp;}
cout<<"Team"<<setw(10)<<"Won"<<setw(4)<<"Draw"<<setw(4)<<"Lost"<<setw(4);
cout<<"GS"<<setw(4)<<"GA"<<setw(4);
for(p=0;p<6;p++){
   temp=table[p];
   team[temp].view_table();}
 

farazzz

کاربر تازه وارد
تاریخ عضویت
7 فوریه 2004
نوشته‌ها
26
لایک‌ها
0
آقا شرمنده:blush: یه مشکل دیگه:
HTML:
case 2:{
int n;
cout<<"Please enter the week you want to see its results:";
cin>>n; //number of week
for(int t=0;t<15;t++){
if(f[t].week==n){
int temp1,temp2;
temp1=f[t].host;
temp2=f[t].guest;
team[temp1].show();
cout<<" "<<f[t].hg<<" - " ;
cout<<f[t].gg<<" ";
team[temp2].show();
cout<<endl;};};}

برای کیس 2 این ارور رو میده :
case bypasses initialization of a local variable

در صورتی که وقتی کیس 1 نبود این ارور رو نمی داد و برنامه درست اجرا می شد.

کد:
case 1:{
int table[6],p,q,r;
for(p=0;p<6;p++)
   table[p]=p;
int temp;
   for(q=0;q<6;q++)
      for(int r=1;r<6;r++)
         if(team[r].point()>team[p].point()){
         temp=q;
         q=r;
         r=temp;}
         else if(team[r].point()==team[p].point())
            if(team[r].avr()>team[p].avr()){
         temp=q;
         q=r;
         r=temp;}
cout<<"Team"<<setw(10)<<"Won"<<setw(4)<<"Draw"<<setw(4)<<"Lost"<<setw(4);
cout<<"GS"<<setw(4)<<"GA"<<setw(4);
for(p=0;p<6;p++){
   temp=table[p];
   team[temp].view_table();}
 

Arman_BTC

کاربر تازه وارد
تاریخ عضویت
28 فوریه 2006
نوشته‌ها
138
لایک‌ها
1
سلام
کد:
cout<<endl;};};}
این سمی کالن های بین کروشه ماله چیه؟
اگه امکان داره کل برنامه رو بزار من اشکالی ندیدم
 

farazzz

کاربر تازه وارد
تاریخ عضویت
7 فوریه 2004
نوشته‌ها
26
لایک‌ها
0
,والا من خودمم نمیدونم ولی تا سمی کالون ها رو نذاشتم ایراد می گرفت;)
این هم کل برنامه:
کد:
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
///////////////////////////////////CLASS////////////////////////////////////////
class teams
{
private:
   char name[20];
	int won;
	int draw;
	int lost;
	int gs;
	int ga;
   int points;
public:
   teams() : won(0),lost(0),draw(0),gs(0),ga(0),points(0)
   {}
   int point(){
   return points;}
   int avr(){
   return (gs-ga);}//end avr
	void get(){
	cin>>name;}//end of get
	void show(){
	cout<<name;}//end of show
	void increase_points(int z,int k)
	{
	if(z>k) {won++;points+=3;}
		else if(z==k) {draw++;points+=1;}
			else {lost++;}}//end of increase_points
	void increase_goals(int z,int k)
	{
	gs+=z;
	ga+=k;}//end of increase_goals
   void view_table(){
   cout<<name<<setw(10)<<won<<setw(6)<<draw<<setw(6);
   cout<<lost<<setw(6)<<gs<<setw(6)<<ga<<setw(6)<<points<<setw(8)<<endl;}
};//end of class declaration
////////////////////////////////////STRUCTURE///////////////////////////////////
struct fixture{
	int host;
	int guest;
	int week;
	int hg;
	int gg;
};//end of structure
/////////////////////////////////////MAIN///////////////////////////////////////
void main(){
	int i;
   char option1;
	fixture f[15];
	teams team[6];
	cout<<"This is the first page of the football league results program \n";
	cout<<"written by Azad University-North Branch students.\n";
	for(i=1;i<7;i++){
		cout<<"Please enter a Name for the team number "<<(i)<<" :";
		team[i].get(); }//gets team names
	cout<<"You entered the following teams:\n";
	for(i=1;i<7;i++){
	cout<<(i)<<". ";
	team[i].show();
   cout<<endl;}
	cout<<"If you have any mistake entering data,Please type the number of the team\n";
   cout<<"to correct it:.\n";
	cout<<"If it doesn't have any mistake press another key to continue.\n";
	cin>>option1;
	while (option1<'7' && option1>'0'){
		team[option1].get();
		cout<<"Another mistake? Type the number:";
		cin>>option1;}
	f[0].host=1;f[0].guest=2;f[0].week=1;
	f[1].host=3;f[1].guest=4;f[1].week=1;
	f[2].host=5;f[2].guest=6;f[2].week=1;
	f[3].host=1;f[3].guest=3;f[3].week=2;
	f[4].host=2;f[4].guest=6;f[4].week=2;
	f[5].host=5;f[5].guest=4;f[5].week=2;
	f[6].host=1;f[6].guest=4;f[6].week=3;
	f[7].host=3;f[7].guest=6;f[7].week=3;
	f[8].host=2;f[8].guest=5;f[8].week=3;
	f[9].host=1;f[9].guest=5;f[9].week=4;
	f[10].host=3;f[10].guest=2;f[10].week=4;
	f[11].host=6;f[11].guest=4;f[11].week=4;
	f[12].host=1;f[12].guest=6;f[12].week=5;
	f[13].host=3;f[13].guest=5;f[13].week=5;
	f[14].host=2;f[14].guest=4;f[14].week=5;

	cout<<"Please enter the results for weeks 1 to 5 :\n";
for(int j=0;j<15;j++){
	int a,b;
	a=f[j].host;
	b=f[j].guest;
   cout<<"week "<<f[j].week<<"   ";
	team[a].show();
	cout<<" - ";
	team[b].show();
	cout<<" :";
	cin>>f[j].hg>>f[j].gg;
	team[a].increase_goals(f[j].hg,f[j].gg);
	team[a].increase_points(f[j].hg,f[j].gg);
	team[b].increase_goals(f[j].gg,f[j].hg);
	team[b].increase_points(f[j].gg,f[j].hg);}
cout<<"You have entered the results successfully.\n";
cout<<"if you want to view the table press 1 and if you want to see results press 2 :\n";
int option2;
cin>>option2;
switch(option2){
case 1:{
   int table[6],p,q,r;
   for(p=1;p<7;p++)
      table[p]=p;
   int temp;
   for(q=1;q<7;q++)
      for(int r=2;r<7;r++)
         if(team[r].point()>team[p].point()){
            temp=q;
            q=r;
            r=temp;}
         else if(team[r].point()==team[p].point())
            if(team[r].avr()>team[p].avr()){
               temp=q;
               q=r;
               r=temp;}
   cout<<"Team"<<setw(10)<<"Won"<<setw(6)<<"Draw"<<setw(6)<<"Lost"<<setw(6);
   cout<<"GS"<<setw(6)<<"GA"<<setw(6)<<"Points"<<setw(8)<<endl;
   for(p=0;p<6;p++){
      temp=table[p];
      team[temp].view_table();}
case 2:{
   int n,t;
   cout<<"Please enter the week you want to see its results:";
   cin>>n; //number of week
   for(t=0;t<15;t++){
   if(f[t].week==n){
      int temp1,temp2;
      temp1=f[t].host;
      temp2=f[t].guest;
      team[temp1].show();
      cout<<" "<<f[t].hg<<" - " ;
      cout<<f[t].gg<<" ";
      team[temp2].show();
      cout<<endl;};};}

}
getch();};}
کیس 1 و کیس 2 هر کدوم به تنهایی اجرا می شن(البته کیس 1 ایراد منطقی داره ولی اجرا میشه) ولی وقتی با هم باشن این ارور رو میده:(
 

MahdiΩ

کاربر تازه وارد
تاریخ عضویت
27 ژانویه 2006
نوشته‌ها
324
لایک‌ها
0
این کارت رو راه میندازه:

کد:
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
///////////////////////////////////CLASS////////////////////////////////////////
class teams
{
private:
   char name[20];
	int won;
	int draw;
	int lost;
	int gs;
	int ga;
   int points;
public:
   teams() : won(0),lost(0),draw(0),gs(0),ga(0),points(0)
   {}
   int point(){
   return points;}
   int avr(){
   return (gs-ga);}//end avr
	void get(){
	cin>>name;}//end of get
	void show(){
	cout<<name;}//end of show
	void increase_points(int z,int k)
	{
	if(z>k) {won++;points+=3;}
		else if(z==k) {draw++;points+=1;}
			else {lost++;}}//end of increase_points
	void increase_goals(int z,int k)
	{
	gs+=z;
	ga+=k;}//end of increase_goals
   void view_table(){
   cout<<name<<setw(10)<<won<<setw(6)<<draw<<setw(6);
   cout<<lost<<setw(6)<<gs<<setw(6)<<ga<<setw(6)<<points<<setw(8)<<endl;}
};//end of class declaration
////////////////////////////////////STRUCTURE///////////////////////////////////
struct fixture{
	int host;
	int guest;
	int week;
	int hg;
	int gg;
};//end of structure
/////////////////////////////////////MAIN///////////////////////////////////////
void main(){
	int i;
   char option1;
	fixture f[15];
	teams team[6];
	cout<<"This is the first page of the football league results program \n";
	cout<<"written by Azad University-North Branch students.\n";
	for(i=1;i<7;i++){
		cout<<"Please enter a Name for the team number "<<(i)<<" :";
		team[i].get(); }//gets team names
	cout<<"You entered the following teams:\n";
	for(i=1;i<7;i++){
	cout<<(i)<<". ";
	team[i].show();
   cout<<endl;}
	cout<<"If you have any mistake entering data,Please type the number of the team\n";
   cout<<"to correct it:.\n";
	cout<<"If it doesn't have any mistake press another key to continue.\n";
	cin>>option1;
	while (option1<'7' && option1>'0'){
		team[option1].get();
		cout<<"Another mistake? Type the number:";
		cin>>option1;}
	f[0].host=1;f[0].guest=2;f[0].week=1;
	f[1].host=3;f[1].guest=4;f[1].week=1;
	f[2].host=5;f[2].guest=6;f[2].week=1;
	f[3].host=1;f[3].guest=3;f[3].week=2;
	f[4].host=2;f[4].guest=6;f[4].week=2;
	f[5].host=5;f[5].guest=4;f[5].week=2;
	f[6].host=1;f[6].guest=4;f[6].week=3;
	f[7].host=3;f[7].guest=6;f[7].week=3;
	f[8].host=2;f[8].guest=5;f[8].week=3;
	f[9].host=1;f[9].guest=5;f[9].week=4;
	f[10].host=3;f[10].guest=2;f[10].week=4;
	f[11].host=6;f[11].guest=4;f[11].week=4;
	f[12].host=1;f[12].guest=6;f[12].week=5;
	f[13].host=3;f[13].guest=5;f[13].week=5;
	f[14].host=2;f[14].guest=4;f[14].week=5;

	cout<<"Please enter the results for weeks 1 to 5 :\n";
for(int j=0;j<15;j++){
	int a,b;
	a=f[j].host;
	b=f[j].guest;
   cout<<"week "<<f[j].week<<"   ";
	team[a].show();
	cout<<" - ";
	team[b].show();
	cout<<" :";
	cin>>f[j].hg>>f[j].gg;
	team[a].increase_goals(f[j].hg,f[j].gg);
	team[a].increase_points(f[j].hg,f[j].gg);
	team[b].increase_goals(f[j].gg,f[j].hg);
	team[b].increase_points(f[j].gg,f[j].hg);}
cout<<"You have entered the results successfully.\n";
cout<<"if you want to view the table press 1 and if you want to see results press 2 :\n";
int option2;
cin>>option2;
switch(option2){
case 1:
   int table[6],p,q;
   for(p=1;p<7;p++)
      table[p]=p;
   int temp;
   for(q=1;q<7;q++)
      for(int r=2;r<7;r++)
	 if(team[r].point()>team[p].point())
	 {
	    temp=q;
	    q=r;
	    r=temp;
	 }
	 else if(team[r].point()==team[p].point())
	    if(team[r].avr()>team[p].avr()){
	       temp=q;
	       q=r;
	       r=temp;}
   cout<<"Team"<<setw(10)<<"Won"<<setw(6)<<"Draw"<<setw(6)<<"Lost"<<setw(6);
   cout<<"GS"<<setw(6)<<"GA"<<setw(6)<<"Points"<<setw(8)<<endl;
   for(p=0;p<6;p++){
      temp=table[p];
      team[temp].view_table();
      break;
case 2:
   int n,t;
   cout<<"Please enter the week you want to see its results:";
   cin>>n; //number of week
   for(t=0;t<15;t++){
   if(f[t].week==n){
      int temp1,temp2;
      temp1=f[t].host;
      temp2=f[t].guest;
      team[temp1].show();
      cout<<" "<<f[t].hg<<" - " ;
      cout<<f[t].gg<<" ";
      team[temp2].show();
      cout<<endl;
      }
     }
     break;
}
getch();
}
}
 

farazzz

کاربر تازه وارد
تاریخ عضویت
7 فوریه 2004
نوشته‌ها
26
لایک‌ها
0
باز هم همون ایراد رو می گیره:(
 

Arman_BTC

کاربر تازه وارد
تاریخ عضویت
28 فوریه 2006
نوشته‌ها
138
لایک‌ها
1
حالا ببین درست شد؟فکر کنم یه } کم گزاشتی
کد:
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
///////////////////////////////////CLASS////////////////////////////////////////
class teams
{
private:
	char name[20];
int won;
int draw;
int lost;
int gs;
int ga;
	int points;
public:
	teams() : won(0),lost(0),draw(0),gs(0),ga(0),points(0)
	{}
	int point(){
	return points;}
	int avr(){
	return (gs-ga);}//end avr
void get(){
cin>>name;}//end of get
void show(){
cout<<name;}//end of show
void increase_points(int z,int k)
{
if(z>k) {won++;points+=3;}
else if(z==k) {draw++;points+=1;}
else {lost++;}}//end of increase_points
void increase_goals(int z,int k)
{
gs+=z;
ga+=k;}//end of increase_goals
	void view_table(){
	cout<<name<<setw(10)<<won<<setw(6)<<draw<<setw(6);
	cout<<lost<<setw(6)<<gs<<setw(6)<<ga<<setw(6)<<points<<setw(8)<<endl;}
};//end of class declaration
////////////////////////////////////STRUCTURE///////////////////////////////////
struct fixture{
int host;
int guest;
int week;
int hg;
int gg;
};//end of structure
/////////////////////////////////////MAIN///////////////////////////////////////
void main(){
int i;
	char option1;
fixture f[15];
teams team[6];
cout<<"This is the first page of the football league results program \n";
cout<<"written by Azad University-North Branch students.\n";
for(i=1;i<7;i++){
cout<<"Please enter a Name for the team number "<<(i)<<" :";
team[i].get(); }//gets team names
cout<<"You entered the following teams:\n";
for(i=1;i<7;i++){
cout<<(i)<<". ";
team[i].show();
	cout<<endl;}
cout<<"If you have any mistake entering data,Please type the number of the team\n";
	cout<<"to correct it:.\n";
cout<<"If it doesn't have any mistake press another key to continue.\n";
cin>>option1;
while (option1<'7' && option1>'0'){
team[option1].get();
cout<<"Another mistake? Type the number:";
cin>>option1;}
f[0].host=1;f[0].guest=2;f[0].week=1;
f[1].host=3;f[1].guest=4;f[1].week=1;
f[2].host=5;f[2].guest=6;f[2].week=1;
f[3].host=1;f[3].guest=3;f[3].week=2;
f[4].host=2;f[4].guest=6;f[4].week=2;
f[5].host=5;f[5].guest=4;f[5].week=2;
f[6].host=1;f[6].guest=4;f[6].week=3;
f[7].host=3;f[7].guest=6;f[7].week=3;
f[8].host=2;f[8].guest=5;f[8].week=3;
f[9].host=1;f[9].guest=5;f[9].week=4;
f[10].host=3;f[10].guest=2;f[10].week=4;
f[11].host=6;f[11].guest=4;f[11].week=4;
f[12].host=1;f[12].guest=6;f[12].week=5;
f[13].host=3;f[13].guest=5;f[13].week=5;
f[14].host=2;f[14].guest=4;f[14].week=5;

cout<<"Please enter the results for weeks 1 to 5 :\n";
for(int j=0;j<15;j++){
int a,b;
a=f[j].host;
b=f[j].guest;
	cout<<"week "<<f[j].week<<"   ";
team[a].show();
cout<<" - ";
team[b].show();
cout<<" :";
cin>>f[j].hg>>f[j].gg;
team[a].increase_goals(f[j].hg,f[j].gg);
team[a].increase_points(f[j].hg,f[j].gg);
team[b].increase_goals(f[j].gg,f[j].hg);
team[b].increase_points(f[j].gg,f[j].hg);}
cout<<"You have entered the results successfully.\n";
cout<<"if you want to view the table press 1 and if you want to see results press 2 :\n";
int option2;
cin>>option2;
switch(option2){

case '1':{
	int table[6],p,q;
	for(p=1;p<7;p++)
		table[p]=p;
	int temp;
	for(q=1;q<7;q++)
		for(int r=2;r<7;r++)
 if(team[r].point()>team[p].point())
 {
	 temp=q;
	 q=r;
	 r=temp;
 }
 else if(team[r].point()==team[p].point())
	 if(team[r].avr()>team[p].avr()){
		 temp=q;
		 q=r;
		 r=temp;}
	cout<<"Team"<<setw(10)<<"Won"<<setw(6)<<"Draw"<<setw(6)<<"Lost"<<setw(6);
	cout<<"GS"<<setw(6)<<"GA"<<setw(6)<<"Points"<<setw(8)<<endl;
	for(p=0;p<6;p++){
		temp=table[p];
		team[temp].view_table();} }
		break;
case '2':{

	int n,t;
	cout<<"Please enter the week you want to see its results:";
	cin>>n; //number of week
	for(t=0;t<15;t++){
	if(f[t].week==n){
		int temp1,temp2;
		temp1=f[t].host;
		temp2=f[t].guest;
		team[temp1].show();
		cout<<" "<<f[t].hg<<" - " ;
		cout<<f[t].gg<<" ";
		team[temp2].show();
		cout<<endl;
		}
	  }}
	  break;
}
getch();
}
 

farazzz

کاربر تازه وارد
تاریخ عضویت
7 فوریه 2004
نوشته‌ها
26
لایک‌ها
0
با } هم مشکل حل نشد ولی کلا switch رو برداشتم بجاش if...else...if گذاشتم درست شد;)
ممنون
 

Arman_BTC

کاربر تازه وارد
تاریخ عضویت
28 فوریه 2006
نوشته‌ها
138
لایک‌ها
1
فراز جان ولی من اجرا میگیرم.شما یه بار دیگه این برنامه رو اجرا کن.
کد:
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
///////////////////////////////////CLASS////////////////////////////////////////
class teams
{
private:
char name[20];
int won;
int draw;
int lost;
int gs;
int ga;
int points;
public:
teams() : won(0),lost(0),draw(0),gs(0),ga(0),points(0)
{}
int point(){
return points;}
int avr(){
return (gs-ga);}//end avr
void get(){
cin>>name;}//end of get
void show(){
cout<<name;}//end of show
void increase_points(int z,int k)
{
if(z>k) {won++;points+=3;}
else if(z==k) {draw++;points+=1;}
else {lost++;}}//end of increase_points
void increase_goals(int z,int k)
{
gs+=z;
ga+=k;}//end of increase_goals
void view_table(){
cout<<name<<setw(10)<<won<<setw(6)<<draw<<setw(6);
cout<<lost<<setw(6)<<gs<<setw(6)<<ga<<setw(6)<<points<<setw(8)<<endl;}
};//end of class declaration
////////////////////////////////////STRUCTURE///////////////////////////////////
struct fixture{
int host;
int guest;
int week;
int hg;
int gg;
};//end of structure
/////////////////////////////////////MAIN///////////////////////////////////////
void main(){
int i;
char option1;
fixture f[15];
teams team[6];
cout<<"This is the first page of the football league results program \n";
cout<<"written by Azad University-North Branch students.\n";
for(i=1;i<7;i++){
cout<<"Please enter a Name for the team number "<<(i)<<" :";
team[i].get(); }//gets team names
cout<<"You entered the following teams:\n";
for(i=1;i<7;i++){
cout<<(i)<<". ";
team[i].show();
cout<<endl;}
cout<<"If you have any mistake entering data,Please type the number of the team\n";
cout<<"to correct it:.\n";
cout<<"If it doesn't have any mistake press another key to continue.\n";
cin>>option1;
while (option1<'7' && option1>'0'){
team[option1].get();
cout<<"Another mistake? Type the number:";
cin>>option1;}
f[0].host=1;f[0].guest=2;f[0].week=1;
f[1].host=3;f[1].guest=4;f[1].week=1;
f[2].host=5;f[2].guest=6;f[2].week=1;
f[3].host=1;f[3].guest=3;f[3].week=2;
f[4].host=2;f[4].guest=6;f[4].week=2;
f[5].host=5;f[5].guest=4;f[5].week=2;
f[6].host=1;f[6].guest=4;f[6].week=3;
f[7].host=3;f[7].guest=6;f[7].week=3;
f[8].host=2;f[8].guest=5;f[8].week=3;
f[9].host=1;f[9].guest=5;f[9].week=4;
f[10].host=3;f[10].guest=2;f[10].week=4;
f[11].host=6;f[11].guest=4;f[11].week=4;
f[12].host=1;f[12].guest=6;f[12].week=5;
f[13].host=3;f[13].guest=5;f[13].week=5;
f[14].host=2;f[14].guest=4;f[14].week=5;

cout<<"Please enter the results for weeks 1 to 5 :\n";
for(int j=0;j<15;j++){
int a,b;
a=f[j].host;
b=f[j].guest;
cout<<"week "<<f[j].week<<"   ";
team[a].show();
cout<<" - ";
team[b].show();
cout<<" :";
cin>>f[j].hg>>f[j].gg;
team[a].increase_goals(f[j].hg,f[j].gg);
team[a].increase_points(f[j].hg,f[j].gg);
team[b].increase_goals(f[j].gg,f[j].hg);
team[b].increase_points(f[j].gg,f[j].hg);}
cout<<"You have entered the results successfully.\n";
cout<<"if you want to view the table press 1 and if you want to see results press 2 :\n";
int option2;
cin>>option2;
switch(option2){

case '1':{
int table[6],p,q;
for(p=1;p<7;p++)
table[p]=p;
int temp;
for(q=1;q<7;q++)
for(int r=2;r<7;r++)
 if(team[r].point()>team[p].point())
 {
 temp=q;
 q=r;
 r=temp;
 }
 else if(team[r].point()==team[p].point())
 if(team[r].avr()>team[p].avr()){
 temp=q;
 q=r;
 r=temp;}
cout<<"Team"<<setw(10)<<"Won"<<setw(6)<<"Draw"<<setw(6)<<"Lost"<<setw(6);
cout<<"GS"<<setw(6)<<"GA"<<setw(6)<<"Points"<<setw(8)<<endl;
for(p=0;p<6;p++){
temp=table[p];
team[temp].view_table();} }
break;
case '2':{

int n,t;
cout<<"Please enter the week you want to see its results:";
cin>>n; //number of week
for(t=0;t<15;t++){
if(f[t].week==n){
int temp1,temp2;
temp1=f[t].host;
temp2=f[t].guest;
team[temp1].show();
cout<<" "<<f[t].hg<<" - " ;
cout<<f[t].gg<<" ";
team[temp2].show();
cout<<endl;
}
  }}
  break;
}
getch();
}
 

farazzz

کاربر تازه وارد
تاریخ عضویت
7 فوریه 2004
نوشته‌ها
26
لایک‌ها
0
درسته.این بار اجرا شد.:) نمیدونم چرا دیروز اجرا نشد؟:(
 
بالا