الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

أرجو المساعة في كود Txt File بلغة C++

بدأه مهندس بشري في 6 ديسمبر 2008 · 5 رد · 662 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

بســم الله الـرحمــن الرحيــم

السلام عليكــم ورحمـة الله وبركاتــه

أخواني الكرام أتمنى منكم المساعدة في برنامج بسيط يحتوي على كود الفرز الفقاعي لملف نصي يتحوي على 4 أسماء طلاب

والمطلوب هو عمل فرز لأسماء الطلبة وأرقام تسجيلهم

هذا هو الكود ... لكنه يحتوي على مشاكل عجزت عن حلها

أتمنى منكم المساعدة العاجلة ولكم جزيل الشكر والامتنان

وكل عام وأنتم بخير

الكود مرفق

txt_File.rar

#2

ضع كودك هنا لنقراءة.

tvquran_6.gif

#3

هذا هو الكود أخي فهدالشلوي

  1.  

  2. #include<stdio.h>
  3. #include<iostream.h>
  4. #include<string.h> #define N 4
  5. #define SWAP(a,b,c) c=a;a=b;b=c;
  6. int j,i;
  7. char NAME[4][80];
  8. int ID[4];
  9. void main()
  10. {
  11. char name[N][80];
  12. int Id[N];
  13. int i;
  14. for(i=0;i<N;i++){
  15. cin>>name[i];
  16. cin>>Id[i];} FILE *f;
  17. f=fopen("student.txt","w");
  18. if(f==NULL)cout<<"File could not be opendn"<<endl;
  19. else
  20. for(i=0;i<N;i++){
  21. fprintf(f,"%s %dn",name[i],Id[i]);
  22. }
  23. fclose(f);
  24. f=fopen("student.txt","r"); int c;
  25. if(f==NULL)cout<<"File could not be openedn";
  26. else{ for(i=0;i<N;i++)
  27. fscanf(f,"%s %dn",NAME[i],ID[i]); for (int iter = 0; iter < (N - 1); iter++)
  28. for ( i = 0; i < (N - 1); i++)
  29. for( j=0;j<80;j++)
  30.  
  31. strcmp(NAME[i],NAME[i+1]);
  32.  
  33.  
  34. SWAP(name[i][j],name[i+1][j],c);
  35.  
  36. for( i=0; i< N; i++){
  37. printf( "%d t", name[i]);
  38. printf(" n");
  39.  
  40.  
  41. }
  42. }
  43. }
  44.  
  45.  

وشكراً على أهتمامك

جزاك الله خيراً

تم تعديل هذه المشاركة بواسطة فهدالشلوي في 7 ديسمبر 2008 في 03:41

#4

هذ الكود عملت لك دوال على عجل جربة وعدل عليه بما يناسب :

الكود عملته بالسي وليس البلس.

  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4. #define MAX_Width_Line 30
  5. #define MAX_Count_Line 4
  6. char list[MAX_Count_Line][MAX_Width_Line];
  7.  
  8.  
  9.  
  10.  
  11. void read_from_user();
  12. void save_to_file();
  13. void read_from_file();
  14. void printall();
  15. void sort();
  16.  
  17. int main()
  18. {
  19.  
  20.  
  21.  
  22. getchar();
  23. return 0;
  24. }
  25.  
  26.  
  27.  
  28.  
  29. void read_from_user()
  30. {
  31. char name[100];
  32. char id[100];
  33. char tmp[MAX_Width_Line];
  34. int i;
  35. for(i=0;i<MAX_Count_Line;i++)
  36. {
  37. printf("Enter Name:");
  38. gets(name);
  39. printf("enter Id:");
  40. gets(id);
  41. strncpy(tmp,name,25);
  42. strcat(tmp," ");
  43. strncat(tmp,id,4);
  44. strcpy(list[i],tmp);
  45. }
  46. save_to_file();
  47. }
  48. void save_to_file()
  49. {
  50. int i;
  51. FILE* my_file;
  52.  
  53. my_file=fopen("student.txt","w");
  54.  
  55. for(i=0;i<MAX_Count_Line;i++)
  56. {
  57. fputs(list[i],my_file);
  58. fputc('n',my_file);
  59. }
  60. fclose(my_file);
  61.  
  62. }
  63.  
  64. void read_from_file()
  65. {
  66. int n=0;
  67. char u[30];
  68. FILE* my_file;
  69. my_file=fopen("student.txt","r");
  70. while(!feof(my_file))
  71. {
  72. fgets(u,30,my_file);
  73. strcpy(list[n++],u);
  74. }
  75. fclose(my_file);
  76. }
  77.  
  78. void printall()
  79. {
  80. int i;
  81. read_from_file();
  82. for(i=0;i<MAX_Count_Line;i++)
  83. {
  84. puts(list[i]);
  85. }
  86.  
  87.  
  88. }
  89.  
  90. void sort()
  91. {
  92. int i,j;
  93. char tm[30];
  94. read_from_file();
  95.  
  96. for(i=0;i<MAX_Count_Line-1;i++)
  97. {
  98. for(j=i;j<MAX_Count_Line;j++)
  99. {
  100. if(strcmp(list[i],list[j])>0)
  101. {
  102. strcpy(tm,list[i]);
  103. strcpy(list[i],list[j]);
  104. strcpy(list[j],tm);
  105. }
  106. }
  107. }
  108. save_to_file();
  109. }
  110.  

tvquran_6.gif

#5

شكراً أخي على المساعدة

لكن المشكلة ما زالت قائمة

أرجو أن تعذرني فأنا مستجد على البرمجة

شكراً لك مرة أخرى

وكل سنة وأنت طيب

تم تعديل هذه المشاركة بواسطة مهندس بشري في 8 ديسمبر 2008 في 02:17

#6

السلام عليكــم ورحمـة الله وبركاتــه

بداً أود أن أشكر لكم حسن أستجابتكم ومساعدتكم لي وإن شاء الله ذلك في موازين حسناتكم

وطبعاً الشكر الجزيل لمشرفنا الرائع فهدالشلوي

الذي أرجو أن يساعدني في حل هذه المشكلة إن شاء الله

المشكلة يا أخواني هي في النتيجة حيث أن هذا البرنامج المفروض أن يرتب الاسماء المدخلة له ولكن يظهر في النتائج أرقام وهذا ما يحيرني جداً

أتمنى أن تساعدوني فأنا محتاج هذا البرنامج لضرورة القصوى

#include<stdio.h>
#include<iostream.h>
#include<string.h>
#define N 4
#define SWAP(a,b,c)    c=a;a=b;b=c;
int j,i;
char NAME[N][80];
int ID[N]; 
void main()
{ 
char name[N][80];
int Id[N];
int i;
for(i=0;i<N;i++){
cout<<"Please Enter the Name of student"<<endl;
cin>>name;
cout<<"Please Enter the ID of student"<<endl;
cin>>Id;} FILE *f;
f=fopen("student.txt","w+");
if(f==NULL)cout<<"File could not be opend\n"<<endl;
else
for(i=0;i<N;i++){
fprintf(f,"%s  %d\n",name,Id);
} int c;
if(f==NULL)
cout<<"File could not be opened\n";
else
{   for(i=0;i<N;i++)

fscanf(f,"%s  %d\n",NAME,ID);    

for (int iter = 0; iter < (N - 1); iter++)  
   for (  i = 0; i < (N - 1); i++)  
      for( j=0;j<80;j++)

     strcmp(NAME,NAME[i+1]);


SWAP(NAME[j],NAME[i+1][j],c);

for( i=0; i< N; i++){
printf( "%d \t", NAME);
printf("   \n");


 }           
} 
}

مواضيع مشابهة