المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : يا عالم يا هو يا اما دحين ترا ما ينفع بعدين أرجو المساعدة



كارولينا
04-04-2005, 11:39 PM
السلام عليكم ورحمة الله وبركاته

أنا عندي واجب في لغة السي في ال structer

وعملتو كلو بس المشكلة عندي في الdelete لما اعمل مسح للبيانات يسير المسح بس المشكلة لما اعمل display مرة تانية تسير بس يطلعلي المكان الا مسحتو والمعلومات الا في على شكل خرابيط

فايش راح اسوي والله يئست من المحاولة ليا اكتر من يومين وانا احاول

الله يخليكم ساعدوني

:17:

كارولينا
04-04-2005, 11:45 PM
#include<stdio.h>
#include<conio.h>
#define SIZE 100
int calculatage(struct rec a[]);
float Calculateincome(struct rec *);

struct date
{ int d;
int m;
int y;
};

struct rec
{
long ID;
char Name[10];
int age;
struct date Birthday;
struct date Hiredday;
float salary;
int grade;
float yearincome;
};
int count=0,i=0,flag=0;
main()
{

struct rec a[SIZE];
char ans,h;
int ch,i,flag=0,id;

do{
clrscr();
printf("\nChoose one from the following:\n"
"\t1. Insert an emoloyee record.\n"
"\t2. Display all records.\n"
"\t3. Update a record.\n"
"\t4. Delete a record.\n"
"\t5. Exit.\n"
"\tEnter your choice: ");
scanf("%d",&ch);

switch(ch)
{
case 1:
{
flag=1;
do
{
printf("\nEnter ID number: ");
scanf("%ld",&a[i].ID);
printf("\nEnter the name of empyolee: ");
scanf("%s",a[i].Name);
printf("\nEnter the Birthday (d/m/y): ");
scanf("%d%d%d",&a[i].Birthday.d,&a[i].Birthday.m,&a[i].Birthday.y);
printf("\nEnter the Hiredday (d/m/y): ");
scanf("%d%d%d",&a[i].Hiredday.d,&a[i].Hiredday.m,&a[i].Hiredday.y);
printf("\nEnter the salary: ");
scanf("%f",&a[i].salary);
printf("\nEnter the grade: ");
scanf("%d",&a[i].grade);
a[i].age=calculatage(&a[i]);
a[i].yearincome=Calculateincome(&a[i]);

printf("\nDo you want to insert new record?");
ans=getche();
if(ans=='y'||ans=='Y')
{clrscr(); i++; count++;}

}while(ans!='n');

//end for

getch();
clrscr();
break;
}

case 2:
{
if(flag==0)
printf("\nThere are no record ro display.");

else
for(i=0;i<=count;i++)
{
printf("\n\nID: %ld.\nName: %s.\nAge: %d.\nBirthday: %d/%d/%d."
"\nHiredday: %d/%d/%d.\n Salary: %.2f.\nGrade: %d.\nYearIncome: %.2f."
,a[i].ID,a[i].Name,a[i].age,a[i].Birthday.d,a[i].Birthday.m
,a[i].Birthday.y,a[i].Hiredday.d,a[i].Hiredday.m
,a[i].Hiredday.y,a[i].salary,a[i].grade,a[i].yearincome);

}
getch();
clrscr();
break;
}//end case 2

case 3:
{ int n;
if(flag==0)
printf("\nThere is no record to update.");

else
{ printf("\nEnter the ID no. that u want to update its information: ");
scanf("%d",&id);

for(i=0;i<=count;i++)
{ if(id==a[i].ID)
{ n=i;
printf("\nEnter ID number: ");
scanf("%ld",&a[n].ID);
printf("\nEnter the name of empyolee: ");
scanf("%s",a[n].Name);
printf("\nEnter the Birthday (d/m/y): ");
scanf("%d%d%d",&a[n].Birthday.d,&a[n].Birthday.m,&a[n].Birthday.y);
printf("\nEnter the Hiredday (d/m/y): ");
scanf("%d%d%d",&a[n].Hiredday.d,&a[n].Hiredday.m,&a[n].Hiredday.y);
printf("\nEnter the salary: ");
scanf("%f",&a[n].salary);
printf("\nEnter the grade: ");
scanf("%d",&a[n].grade);
a[n].age=calculatage(&a[n]);
a[n].yearincome=Calculateincome(&a[n]);
}
}
if(i>count)
printf("\nThe ID not found");
}
getch();
clrscr();
break;}//end case 3

case 4:
{ int n;
if(flag==0)
printf("\nThese is no record to delete");

else
{printf("\nEnter the ID no. that you want to delete its record: ");
scanf("%d",&id);
for(i=0;i<count;i++)
{ if(id==a[i].ID)
{n=i;
for(n;n<=count;n++)
a[n]=a[n+1];
break;}

}
if(i>count)
printf("\nThe ID not found");

}
getch();
clrscr();
break;
}

case 5:
{
printf("Thank you for using our program>>>>Goodbye");
goto end;
}

default:
printf("\nOoOoPs!!! you enter the wrong choich");

} //end switch

printf("\n Do you want to choose other choice ?");
h=getche();
clrscr();
}while(h=='y'||h=='Y');

end:
getch();
return 0;
}

int calculatage(struct rec a[])
{
return (a[i].age=2005-a[i].Birthday.y);
}

float Calculateincome(struct rec *a)
{
return a->salary *12.0;
}



ودا الكود بس والله ما ادري ليش طالع بالمقلوب


ساعدوني الله يخليكم

BOOOB_2002
05-04-2005, 02:04 AM
اقول ارفقي الكود بمستند نصي وحطيه هنا :)

oms
05-04-2005, 03:07 PM
try to copy structure in delete by elment by element if it still dosn't work just use denug

ibn_alqalam
05-04-2005, 04:27 PM
لديك مشاكل عدة, و لكن اكبر مشكلة ليست من صنعك.

انك تستخدمين دالات الطباعة من conio.h و هي فقط متوفرة في الدوس MS DOS. اّخر اصدارات ويندوز لاتدعم تلك الخدمات بشكل كافئ, لذا يجب ان تستخدمي دالات القراء و الكتابة العامة للغة برمجة سي, او تستخدمي و اجهة رسومية و دع منك من الدوس.

كل ما قمت به هو حذف ضمن conio.h و ترجمت دالاته الى دالات سي. مثلا, getche و getch الى getchar. و حذفت دالة مسح الشاشة clrscr.

اذا تريدين فحص مشكلة, لا تمسحي الشاشة! ذلك بمثابة اطفاء النور قبل ان تبدا بالقراءة!

مع اقل قدر ممكن من التعديلات, و هو يعمل كما يظهر في الصورة المرفقة. يعمل, و لكن ليس بشكل جيد.




#include <stdio.h>
//#include <conio.h>

#define SIZE 100

struct date
{ int d;
int m;
int y;
};

struct rec
{
long ID;
char Name[10];
int age;
struct date Birthday;
struct date Hiredday;
float salary;
int grade;
float yearincome;
};

int calculatage(struct rec a[]);
float Calculateincome(struct rec *a);


int count=0,i=0,flag=0;

main()
{

struct rec a[SIZE];
char ans,h;
int ch,i,flag=0,id;

do{
// clrscr();
printf("\nChoose one from the following:\n"
"\t1. Insert an emoloyee record.\n"
"\t2. Display all records.\n"
"\t3. Update a record.\n"
"\t4. Delete a record.\n"
"\t5. Exit.\n"
"\tEnter your choice: ");
scanf("%d",&ch);

switch(ch)
{
case 1:
{
flag=1;
do
{
printf("\nEnter ID number: ");
scanf("%ld",&a[i].ID);
printf("\nEnter the name of empyolee: ");
scanf("%s",a[i].Name);
printf("\nEnter the Birthday (d/m/y): ");
scanf("%d%d%d",&a[i].Birthday.d,&a[i].Birthday.m,&a[i].Birthday.y);
printf("\nEnter the Hiredday (d/m/y): ");
scanf("%d%d%d",&a[i].Hiredday.d,&a[i].Hiredday.m,&a[i].Hiredday.y);
printf("\nEnter the salary: ");
scanf("%f",&a[i].salary);
printf("\nEnter the grade: ");
scanf("%d",&a[i].grade);
a[i].age=calculatage(&a[i]);
a[i].yearincome=Calculateincome(&a[i]);

i++;
count++;
printf("\nDo you want to insert new record?");
ans=getchar();
if(ans=='y'||ans=='Y')
{/*clrscr();
i++; count++;}*/
}
}while(ans!='n');

//end for

getchar();
//clrscr();
break;
}

case 2:
{
printf ("displaying");
fflush (stdout);
if(flag==0)
printf("\nThere are no record ro display.");

else
for(i=0;i<=count;i++)
{
printf("\n\nID: %ld.\nName: %s.\nAge: %d.\nBirthday: %d/%d/%d."
"\nHiredday: %d/%d/%d.\n Salary: %.2f.\nGrade: %d.\nYearIncome: %.2f."
,a[i].ID,a[i].Name,a[i].age,a[i].Birthday.d,a[i].Birthday.m
,a[i].Birthday.y,a[i].Hiredday.d,a[i].Hiredday.m
,a[i].Hiredday.y,a[i].salary,a[i].grade,a[i].yearincome);

}
getchar();
//clrscr();
break;
}//end case 2

case 3:
{ int n;
if(flag==0)
printf("\nThere is no record to update.");

else
{ printf("\nEnter the ID no. that u want to update its information: ");
scanf("%d",&id);

for(i=0;i<=count;i++)
{ if(id==a[i].ID)
{ n=i;
printf("\nEnter ID number: ");
scanf("%ld",&a[n].ID);
printf("\nEnter the name of empyolee: ");
scanf("%s",a[n].Name);
printf("\nEnter the Birthday (d/m/y): ");
scanf("%d%d%d",&a[n].Birthday.d,&a[n].Birthday.m,&a[n].Birthday.y);
printf("\nEnter the Hiredday (d/m/y): ");
scanf("%d%d%d",&a[n].Hiredday.d,&a[n].Hiredday.m,&a[n].Hiredday.y);
printf("\nEnter the salary: ");
scanf("%f",&a[n].salary);
printf("\nEnter the grade: ");
scanf("%d",&a[n].grade);
a[n].age=calculatage(&a[n]);
a[n].yearincome=Calculateincome(&a[n]);
}
}
if(i>count)
printf("\nThe ID not found");
}
getchar();
//clrscr();
break;}//end case 3

case 4:
{ int n;
if(flag==0)
printf("\nThese is no record to delete");

else
{printf("\nEnter the ID no. that you want to delete its record: ");
scanf("%d",&id);
for(i=0;i<count;i++)
{ if(id==a[i].ID)
{n=i;
for(n;n<=count;n++)
a[n]=a[n+1];
break;}

}
if(i>count)
printf("\nThe ID not found");

}
getchar();
//clrscr();
break;
}

case 5:
{
printf("Thank you for using our program>>>>Goodbye");
goto end;
}

default:
printf("\nOoOoPs!!! you enter the wrong choich");

} //end switch

printf("\n Do you want to choose other choice ?");
h=getchar();
//clrscr();
}while(h=='y'||h=='Y');

end:
getchar();
return 0;
}

int calculatage(struct rec a[])
{
return (a[i].age=2005-a[i].Birthday.y);
}

float Calculateincome(struct rec *a)
{
return a->salary *12.0;
}