اينم جواب پروژه شون :
کد PHP:
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#include <iomanip.h>
struct Student
{
int ID;
char FirstName[20];
char LastName[30];
double Mark;
} st;
struct Student *classA[30];
void new_student(int st_id);
void Print_StudentList();
float CalcAverage();
void Sort_Students();
int StudentCount;
float ClassAverage;
void main()
{
clrscr();
cout << "\Enter Student Number :";
int i;
cin >> StudentCount;
for (i=1;i<=StudentCount;i++)
{
new_student(i);
}
clrscr();
ClassAverage = CalcAverage();
printf("\n\n\n ClassA Average : %.2f ",ClassAverage);
Sort_Students();
Print_StudentList();
getch();
}
void new_student(int st_id)
{
classA[st_id] = classA[0] + (sizeof(st) * st_id) ;
classA[st_id]->ID = st_id;
cout << "\nEnter Student[" << st_id << "].LastName :";
cin >> classA[st_id]->LastName;
cout << "\nEnter Student[" << st_id << "].FirstName:";
cin >> classA[st_id]->FirstName;
cout << "\nEnter Student[" << st_id << "].Mark:";
cin >> classA[st_id]->Mark;
}
void Print_StudentList()
{
int i;
//.................................
//... Save In File ................
//.................................
FILE *fp;
char filename[20] = "c:\\st.txt";
fp = fopen(filename,"w");
if (fp!=NULL)
{
fprintf(fp,"\nStudent List : ");
for (i=1;i<=StudentCount;i++)
{
if (classA[i]-> Mark > ClassAverage)
fprintf(fp,"\n%d : %s %s : %.2f ",classA[i]->ID,classA[i]->FirstName,classA[i]->LastName,classA[i]->Mark);
else
break;
}
fclose(fp);
cout << "\nList Of Students Save in File : \"" << filename << "\"\n";
}
else
{
cout << "\nError On Create File " << filename << "\n";
}
//.................................
//... Preview On Screen ...........
//.................................
cout << "\n\nStudentList\n\n";
for (i=1;i<=StudentCount;i++)
{
if (classA[i]-> Mark > ClassAverage)
cout << "\n" << classA[i]->ID << ": " << classA[i]->FirstName << " | " << classA[i]->LastName << " | " << classA[i]->Mark;
else
break;
}
//.................................
//.................................
//.................................
}
float CalcAverage()
{
int i;
float sumMarks=0;
for (i=1;i<=StudentCount;i++)
{
sumMarks += classA[i]->Mark;
}
return (sumMarks / StudentCount);
}
void Sort_Students()
{
int i,j;
for (i=1;i<=StudentCount;i++)
{
for (j=i+1;j<=StudentCount;j++)
{
if (classA[j]->Mark > classA[i]->Mark )
{
struct Student *Temp;
Temp = classA[j];
classA[j] = classA[i];
classA[i] = Temp;
}
}
}
}
علاقه مندی ها (Bookmarks)