PDA

View Full Version : خطای Fault: access violation at



Collector
پنج شنبه 15 دی 1390, 13:23 عصر
سلام

وقتی تابع Min_Age رو فراخوانی میکنم و بعد Max_Age رو این ارور رو میده.
و یا یه تابع رو دو بار فراخوانی کنم. کامپالر Borland 5.02


Thread stopped C:\DOCUMENTS AND
SETTINGS\ADMIN\DESKTOP\33\111
1.exe: Fault: access violation at
0x40e3b5: read of address 0x402f4c06


#include <iostream.h>
#include <cstring.h>
#include <conio.h>

#define Max_Stu 1
int Count = 0 , Any;

void Insert(string First_Name[],string Last_Name[],float Avg[],float Stu_Code[],int Birth_Day[],string Location_Birth[]);
void Min_Age(string First_Name[],string Last_Name[],float Avg[],float Stu_Code[],int Birth_Day[],string Location_Birth[]);
void Max_Age(string First_Name[],string Last_Name[],float Avg[],float Stu_Code[],int Birth_Day[],string Location_Birth[]);

void Max_Age(string First_Name[],string Last_Name[],float Avg[],float Stu_Code[],int Birth_Day[],string Location_Birth[])
{
float Avg_1[Max_Stu];
float Stu_Code_1[Max_Stu];
int Birth_Day_1[Max_Stu];

string First_Name_1[Max_Stu];
string Last_Name_1[Max_Stu];
string Location_Birth_1[Max_Stu];

for(int i=0;i <= Max_Stu;i++)
{
Birth_Day_1[i] = Birth_Day[i];
}

for(int i=0;i <= Max_Stu;i++)
{
Stu_Code_1[i] = Stu_Code[i];
}

for(int i=0;i <= Max_Stu;i++)
{
First_Name_1[i] = First_Name[i];
}

for(int i=0;i <= Max_Stu;i++)
{
Last_Name_1[i] = Last_Name[i];
}

for(int i=0;i <= Max_Stu;i++)
{
Avg_1[i] = Avg[i];
}

for(int i=0;i <= Max_Stu;i++)
{
Location_Birth_1[i] = Location_Birth[i];
}

int i,j;
int x;
for(i = 0; i < Max_Stu - 1; i++)
for(j = i + 1; j < Max_Stu; j++)
if (Birth_Day_1[i] < Birth_Day_1[j])
{
x = Birth_Day_1[i];

Birth_Day_1[i] = Birth_Day_1[j];

Stu_Code_1[i] = Stu_Code_1[j];
First_Name_1[i] = First_Name_1[j];
Last_Name_1[i] = Last_Name_1[j];
Avg_1[i] = Avg_1[j];
Location_Birth_1[i] = Location_Birth_1[j];

Birth_Day_1[j] = x;
}

clrscr();
cout<<"Max Birth Day is = "<< Birth_Day_1[0]<<endl<<endl;
cout<<"Stu Code is = "<< Stu_Code_1[0]<<endl;
cout<<"First Name is = "<< First_Name_1[0]<<endl;
cout<<"Last Name is = "<< Last_Name_1[0]<<endl;
cout<<"Avg is = "<< Avg_1[0]<<endl;
cout<<"Location Birth is = "<< Location_Birth_1[0]<<endl;

Any = getche();
clrscr();
}


void Min_Age(string First_Name[],string Last_Name[],float Avg[],float Stu_Code[],int Birth_Day[],string Location_Birth[])
{
float Avg_2[Max_Stu];
float Stu_Code_2[Max_Stu];
int Birth_Day_2[Max_Stu];

string First_Name_2[Max_Stu];
string Last_Name_2[Max_Stu];
string Location_Birth_2[Max_Stu];

for(int i=0;i <= Max_Stu;i++)
{
Birth_Day_2[i] = Birth_Day[i];
}

for(int i=0;i <= Max_Stu;i++)
{
Stu_Code_2[i] = Stu_Code[i];
}

for(int i=0;i <= Max_Stu;i++)
{
First_Name_2[i] = First_Name[i];
}

for(int i=0;i <= Max_Stu;i++)
{
Last_Name_2[i] = Last_Name[i];
}

for(int i=0;i <= Max_Stu;i++)
{
Avg_2[i] = Avg[i];
}

for(int i=0;i <= Max_Stu;i++)
{
Location_Birth_2[i] = Location_Birth[i];
}

int i,j;
int x;
for(i = 0; i < Max_Stu - 1; i++)
for(j = i + 1; j < Max_Stu; j++)
if (Birth_Day_2[i] > Birth_Day_2[j])
{
x = Birth_Day_2[i];

Birth_Day_2[i] = Birth_Day_2[j];

Stu_Code_2[i] = Stu_Code_2[j];
First_Name_2[i] = First_Name_2[j];
Last_Name_2[i] = Last_Name_2[j];
Avg_2[i] = Avg_2[j];
Location_Birth_2[i] = Location_Birth_2[j];

Birth_Day_2[j] = x;
}

clrscr();
cout<<"Min Birth Day is = "<< Birth_Day_2[0]<<endl<<endl;
cout<<"Stu Code is = "<< Stu_Code_2[0]<<endl;
cout<<"First Name is = "<< First_Name_2[0]<<endl;
cout<<"Last Name is = "<< Last_Name_2[0]<<endl;
cout<<"Avg is = "<< Avg_2[0]<<endl;
cout<<"Location Birth is = "<< Location_Birth_2[0]<<endl;

Any = getche();
clrscr();
}

void Insert(string First_Name[],string Last_Name[],float Avg[],float Stu_Code[],int Birth_Day[],string Location_Birth[])
{
int count;

clrscr();
cout<<"*** WellCome To Insert New Student ***\n";

for(int i = 0 ; i < Max_Stu; i++)
{
cout<<"\n---------- Enter Stu_Code Of Student : ";
cin>> Stu_Code[i];

cout<<"\n---------- Enter First Name Of Student : ";
cin>> First_Name[i];

cout<<"\n---------- Enter Last Name Of Student : ";
cin>> Last_Name[i];

cout<<"\n---------- Enter Birth Day Of Student : ";
cin>> Birth_Day[i];

cout<<"\n---------- Enter Location_Birth Of Student : ";
cin>> Location_Birth[i];

cout<<"\n---------- Enter Avg Of Student : ";
cin>> Avg[i];

clrscr();
}

Any = getche();
clrscr();
}

int main(void)
{
int Menu = 0;

string First_Name[Max_Stu];
string Last_Name[Max_Stu];
string Location_Birth[Max_Stu];

float Avg[Max_Stu];
float Stu_Code[Max_Stu];
int Birth_Day[Max_Stu];

for(int Tek = 0 ; Tek < 10 ; Tek++)
{
cout<<" *_*_*_* Menu *_*_*_*"<<endl<<endl;
cout<<"| 1 | --> Insert"<<endl;
cout<<"| 2 | --> Min Age"<<endl;
cout<<"| 3 | --> Max Age"<<endl;
cout<<"| 7 | --> Exit"<<endl;

cout<<"\n\nPlease Enter Number : ";
cin >> Menu;
cout<<"\n";

if (Menu == 1) { Insert(First_Name, Last_Name, Avg, Stu_Code, Birth_Day,Location_Birth) ; }
if (Menu == 2) { Min_Age(First_Name, Last_Name, Avg, Stu_Code, Birth_Day,Location_Birth) ; }
if (Menu == 3) { Max_Age(First_Name, Last_Name, Avg, Stu_Code, Birth_Day,Location_Birth) ; }

if (Menu == 7)
{
clrscr();
cout<<"\n *_*_*_*_* Good Bye *_*_*_*_*";
break;
Any = getch();
}
Menu = 0;
}
return 0;
}