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

ممكن مساعده اذا اتكرمتوا

مغلق
بدأه الراسب في 15 مايو 2004 · 6 رد · 629 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

برنامج طلاب والمطلوب الاجراءات التالية:

1- display class

2 - sort by name

3- sort by number

3- sort by grade

4- first in class

5- first in each subject

6- add new student

7- exit

المدخلات :

تحديد عدد الطلاب

ادخال الاسم و الرقم والدرجة

اذا ممكن بس اعرف ايش الفشال في البرنامج دا مع اني عملته بالمصفوفات بس ابغاه بالتراكيب

المحاولة:

[CODE]#include<iostream>
using namespace std;


void SortNames(struct student stu[n],int i)
{
	for(int i=0;i<n;i++)
  for(int j=0;j<n;j++)
 	 if(stu.name<stu[j].name)
 	 {

    string s=stu.name;
    stu.name=stu[j].name;
    stu[j].name=s;

       float t=stu.grd;
    stu.grd=stu[j].grd;
    stu[j].grd=t;

    
    int m=stu.num;
    stu.num=stu[j].num;
    stu[j].num=m;
 	 }
 	 for(i=0;i<n;i++)
	{
  cout<<"the name\t\t"<<"the number\t\t"<<"the grade\t\t";
  cout<<stu.name<<stu.num<<stu.grd;
	}
}

void Sortnumber(struct student stu[n],int i,int n)
{
	for(int i=0;i<n;i++)
  for(int j=0;j<n;j++)
 	 if(stu.num<stu[j].num)
 	 {
    string s=stu.name;
    stu.name=stu[j].name;
    stu[j].name=s;

       float t=stu.grd;
    stu.grd=stu[j].grd;
    stu[j].grd=t;

    
    int m=stu.num;
    stu.num=stu[j].num;
    stu[j].num=m;
 	 }
    for(i=0;i<n;i++)
	{
  cout<<"the name\t\t"<<"the number\t\t"<<"the grade\t\t";
  cout<<stu.name<<stu.num<<stu.grd;
	}
  
}
void sortgrade(struct student stu[n],int i,int n)
{
	for(int i=0;i<n;i++)
  for(int j=0;j<n;j++)
      if(stu.grd>stu[j].grd)
 	 {
 	 
    string s=stu.name;
    stu.name=stu[j].name;
    stu[j].name=s;

       float t=stu.grd;
    stu.grd=stu[j].grd;
    stu[j].grd=t;

    
    int m=stu.num;
    stu.num=stu[j].num;
    stu[j].num=m;
 	 }
 	 for(i=0;i<n;i++)
	{
  cout<<"the name\t\t"<<"the number\t\t"<<"the grade\t\t";
  cout<<stu.name<<stu.num<<stu.grd;
	}  
}

int Searchname(struct student stu[n],int i,int n,char key)       
{
	for(int i=0;i<n;i++)
  if(names==key)
  {
    cout<<"\n"<<"the name"<<"\t"<<"the number"<<"\t"<<"total"<<"\t"<<"mark"<<"\t"<<"average"<<"\t";
    cout<<"\n"<<names<<"\t\t"<<a<<"\t\t"<<total<<"\t"<<mark<<"\t"<<x<<endl;
  }
 	 return 1;
	//	return -1;
}
  

int menu()
{
	int choice;
	cout<<"\nCHOOSE ONE OF  THE FOLLOWING:";
    cout<<"\n1-SHOW ALL INFORMATION FOR STUDENT.";
	cout<<"\n2-NAMES IN SORTED .";
	cout<<"\n3-NUMBER IN SORTED .";
    cout<<"\n4-TOTAL IN SORTED .";
	cout<<"\n5-SEARCH ABOUT NAME.";
	cout<<"\n6-SEARCH ABOUT NUMBER.";
	cout<<"\n7-EXIT.";
	cin>>choice;
	return choice;
}

main()
{
	struct student stu[n]
	{
  char name;
  float grd;
  int num;
	};
	int n=100;
	cout<<"Enter the number of student"<<endl;
	cin>>n;
	struct student stu[100];
	int i;
for (i=0;i<n;i++)
{
 cout<<"name of student["<<i+1<<"]";
 cin>>stu.name;
 cout<<"grade of student["<<i+1<<"]";
 cin>>stu.grd;
 cout<<"number of student["<<i+1<<"]";
 cin>>stu.num;
}
	while(true)
	{
  int choice;
     choice=menu();
  if(choice==0)
  {
          ntm(student stu[],i,n);
  }
        else if(choice==1)
  {
           SortNames(student stu[],i,n);
  }
  else if(choice==2)
  {
           Sortnumber(student stu[],i,n);
  }
  else if(choice==3)
  {
           sortTotal(student stu[],i,n); 
  }
  else if(choice==4)
  {
 	 cout<<"\n\nEnter A Name To Be Searched For:";
         cin>>key;
         d=Searchname(stu[].name,stu[].num,stu[].grd,i,n);            
         if(d>=1)
         cout<<"\nThe Name Is Found.\n"<<endl;
         else
         cout<<"\nThe Name Is Not Found.\n";
  }

  else if(choice==7)
 	 break;
  else
 	 cout<<"\nBad Choice Try Again.\n";
	}
}

تم تعديل هذه المشاركة بواسطة HGB في 15 مايو 2004 في 00:30

#2

السلام عليكم ,,

لماذا هذا الاهمال ؟ اليوم الصبح التسليم يعني بعد أقل من 8 ساعات ,,

الله يعينك ,, سأراجع الكود وأحاول مااستطعت هذا اليوم قبل أن انتهي ,,

أمر آخر ماذا تقصد بالتراكيب ؟ وماهي المصفوفات هل هي الكلاسات أم المصفوفات العادية ؟

أمر أخير أتمنى أن لايتم تخصيص السؤال لاحقا باسم شخص معين ,, ليكون عاما ويستطيع باقي الأعضاء الاجابة عليك ,,

banner_60_468.gif

NOTHING IS IMPOSSIBLE

#3

اول شي والله يا اخي اناكان في بالي انه مفوفات العادية مو كلاسات

بس جاني تلفون عكر مزاجي انه لازم يسير تراكيب

structure

حاولت اني احولوا من اول

بس مني قادر

انت حاولي اذا قدرت ولك مني صالح الدعاء من المدينة المنورة وفي الحرم

#4

ارجوك حاول انا ترى حتجنن ولازم اسلمو بعد 6 ساعات ...هادي الظروف ...ماادري اذا وصل ندائي لك او للجميع

#5

برنامجك فيه أكثر من 102 غلط !!

وهو كبير وليس بالهين ويحتاج لوقت ,,

وأنت قلت أنك كتبت الكود من قبل كاملا بدون تراكيب ,, صح ؟ ثم فجأة أخبروك أنه يجب استخدام التراكيب صح ؟

أعطيني الكود الذي ليس به تراكيب وسأحاول أن أساعدك باذن الله ,,

لأن الوقت ضيق حاليا ,,

banner_60_468.gif

NOTHING IS IMPOSSIBLE

#6
#include<iostream>
#include<string>
using namespace std;
void SortNames(string names[],int z,int a[],int y,float total[],float x[],string mark[]);
void bubblesort(int a[],int n);
void Sortnumber(string names[],int a[],int z,int y,float total[],float x[],string mark[]);
int Searchname(string names[],int z,int a[],float total[],float x[],string key,string mark[]);
int Searchnumber(string names[],int z,int a[],float total[],float x[],int num,string mark[]);
void TheTotal(float total[],float x[],int z,int a[],int y,string names[],string mark[]);
void ntm(string names[],float total[],float x[],int a[],int z,int y,string mark[]);
int menu();
void main()
{

    const int m=100,n=10;
    int i,j,z,y,d,choice;
	string mark[m];
	string names[m],key;
	int a[m],num;
	float x[m];
	float grades[m][n];
 	 float total[m],t,b;
	cout<<"Enter The Numbers Of Students"<<endl;
	cin>>z;
	cout<<"Enter The Numbers Of Subjects"<<endl;
	cin>>y;
	for(i=0;i<z;i++)
	{
        cout<<"\n\nEnter the Name Of Student:";
     cin>>names;
  cout<<"Enter the Number of student:";
  cin>>a;
   	 cout<<"Enter The Grades For ";
        cout<<names<<":"<<endl;
        t=0,b=0;
   	 for(j=0;j<y;j++)
  {
 	 cout<<"Subject["<<j+1<<"]: ";
       	 cin>>grades[j];       
         b=b+grades[j];
       	 t=b;
       	 total=t;  
  }
  
  
 	 }
	for(i=0;i<y;i++)
    x=total/(y*20);
	while(true)
	{
     choice=menu();
  if(choice==1)
  {
          ntm(names,total,x,a,z,y,mark);
  }
        else if(choice==2)
  {
           SortNames(names,z,a,y,total,x,mark);
  }
  else if(choice==3)
  {
           Sortnumber(names,a,z,y,total,x,mark);
  }
  else if(choice==4)
  {
           TheTotal(total,x,z,a,y,names,mark); 
  }
  else if(choice==5)
  {
 	 cout<<"\n\nEnter A Name To Be Searched For:";
         cin>>key;
         d=Searchname(names,z,a,total,x,key,mark);            
         if(d>=1)
         cout<<"\nThe Name Is Found.\n"<<endl;
         else
         cout<<"\nThe Name Is Not Found.\n";
  }
  else if(choice==6)
  {
 	 cout<<"\n\nEnter A Number To Be Searched For:";
         cin>>num;
         d=Searchnumber(names,z,a,total,x,num,mark);            
         if(d>=1)
         cout<<"\nThe Number Is Found.\n"<<endl;
         else
         cout<<"\nThe Number Is Not Found.\n";
  }
  else if(choice==7)
 	 break;
  else
 	 cout<<"\nBad Choice Try Again.\n";
	}
}
void ntm(string names[],float total[],float x[],int a[],int z,int y,string mark[])
{
	float avg;
          cout<<"\n"<<"the name"<<"\t"<<"the number"<<"\t"<<"total"<<"\t"<<"mark"<<"\t"<<"averge"<<"\t";  
          for(int i=0;i<z;i++)
    {
         avg=total/y;
         if(avg>=90)
      mark='a';                
          else if(avg>=80)
      mark='b';
         else if(avg>=70)
      mark='c';
         else if(avg>=60)
         mark='d';
         else
      mark='f';
            cout<<"\n"<<names<<"\t\t"<<a<<"\t\t"<<total<<"\t"<<mark<<"\t"<<x<<"\t";
    }
}
void SortNames(string names[],int z,int a[],int y,float total[],float x[],string mark[])
{
	for(int i=0;i<z;i++)
  for(int j=0;j<z;j++)
 	 if(names<names[j])
 	 {
    int x=a;
    a=a[j];
    a[j]=x;

    string s=names;
    names=names[j];
    names[j]=s;

       float t=total;
    total=total[j];
    total[j]=t;
 	 }
    ntm(names,total,x,a,z,y,mark);

}
void bubblesort(int a[],int n)
{
	int t,i,j;
	for(i=0;i<n-1;i++)
  for(j=i+1;j<n;j++)
 	 if(a>a[j])
 	 {t=a;
 	 a=a[j];
 	 a[j]=t;
 	 }
 	 return;
}
void Sortnumber(string names[],int a[],int z,int y,float total[],float x[],string mark[])
{
	for(int i=0;i<z;i++)
  for(int j=0;j<z;j++)
 	 if(a<a[j])
 	 {
    int x=a;
    a=a[j];
    a[j]=x;

    string s=names;
    names=names[j];
    names[j]=s;

       float t=total;
    total=total[j];
    total[j]=t;
 	 }
    ntm(names,total,x,a,z,y,mark);
  
}
void TheTotal(float total[],float x[],int z,int a[],int y,string names[],string mark[])
{
	for(int i=0;i<z;i++)
  for(int j=0;j<z;j++)
      if(total>total[j])
 	 {
    int x=a;
    a=a[j];
    a[j]=x;

    string s=names;
    names=names[j];
    names[j]=s;

       float t=total;
    total=total[j];
    total[j]=t;
 	 }
    ntm(names,total,x,a,z,y,mark);  
}

int Searchname(string names[],int z,int a[],float total[],float x[],string key,string mark[])       
{
	for(int i=0;i<z;i++)
  if(names==key)
  {
    cout<<"\n"<<"the name"<<"\t"<<"the number"<<"\t"<<"total"<<"\t"<<"mark"<<"\t"<<"average"<<"\t";
    cout<<"\n"<<names<<"\t\t"<<a<<"\t\t"<<total<<"\t"<<mark<<"\t"<<x<<endl;
  }
 	 return 1;
	//	return -1;
}
  

int Searchnumber(string names[],int z,int a[],float total[],float x[],int num,string mark[])       
{
	for(int i=0;i<z;i++)
  if(a==num)
  {
    cout<<"\n"<<"the name"<<"\t"<<"the number"<<"\t"<<"total"<<"\t"<<"mark"<<"\t"<<"average"<<"\t";
    cout<<"\n"<<names<<"\t\t"<<a<<"\t\t"<<total<<"\t"<<mark<<"\t"<<x<<endl;
  }
 	 return 1;
  return -1;
}
int menu()
{
	int choice;
	cout<<"\nCHOOSE ONE OF  THE FOLLOWING:";
    cout<<"\n1-SHOW ALL INFORMATION FOR STUDENT.";
	cout<<"\n2-NAMES IN SORTED .";
	cout<<"\n3-NUMBER IN SORTED .";
    cout<<"\n4-TOTAL IN SORTED .";
	cout<<"\n5-SEARCH ABOUT NAME.";
	cout<<"\n6-SEARCH ABOUT NUMBER.";
	cout<<"\n7-EXIT.";
	cin>>choice;
	return choice;
}

تم تعديل هذه المشاركة بواسطة HGB في 15 مايو 2004 في 13:51

#7

السلام عليكم ,,

أخي الكريم ,, اعذرني فوالله كل ماأنظر الى كودك أشيل هم ,, هو سهل,, لكن تغييره يأخذ وقتا طويلا ,, على الأقل ساعة ,, حتى أتاكد من تناغمه وبأنه يعمل ,,

لذا سأريك الطريقة وحاول انت وستفلح باذن الله ,,

فقط اكتب

struct Student
{
int dgree 1;
int dgree2;
char name[20];
int number;
.
.
.
.
etc
}

ومرر القيم للدوال بعد تعريف متغير من النوع Student في Main ,, حيث استدعاء القيم الخاصة بال Student كالتالي ,,

void main()
{
Student s[10];
s[0].Name;
s[0].Number;
[

بهذه الطريقة أنشانا 10 طلاب Student ,, ويمكن ان نقوم بملأ بياناتهم ,, فبدل مانقول ,,

cin>>name;

نقول ,,

cin>>s[0].Name;

أرجو أن تكون الطريقة واضحة ,,

banner_60_468.gif

NOTHING IS IMPOSSIBLE

هذا الموضوع مغلق.

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