برنامه پایگاه داده ابتدایی با استفاده از struct
توجه: برنامه کامل نیست. قسمت پایگاه داده کامل شده اما قسمت انجام عملیات ناقص است!
#include <iostream>
#include <conio.h>
#include<string.h>
using namespace std;
struct student {
string f_name;
string l_name;
string std_no;
string code;
int total_pass;
double num[100]={-1};
double ave;
};
main()
{
student* std;
int c,i,j;
cout<<"please enter number of student: ";
cin>>c;
std=new student[c];
cout<<endl<<"----please complete information of each student----"<<endl<<endl;
for( i=0;i<c;i++)
{
cout<<"fname: ";
cin>>std[i].f_name;
cout<<"lname: ";
cin>>std[i].l_name;
cout<<"studebt NO: ";
cin>>std[i].std_no;
cout<<"Code: ";
cin>>std[i].code;
cout<<"Pass course: ";
cin>>std[i].total_pass;
for(int j=0;j<std[i].total_pass;j++)
{
cout<<"course "<<j+1<<" : ";
cin>>std[i].num[j];
}
cout<<"average: ";
cin>>std[i].ave;
cout<<endl<<"-----------------------"<<endl;
}
int select;
cout<<"now select number for do task "<<endl;
cout<<"1>>sort student by lname and print"<<endl;
cout<<"2>>sort student by average and print"<<endl;
cout<<"3>>print informations of pass student in all course or have only one unpass "<<endl<<endl;
cout<<">>> ";
cin>>select;
if(select==1)
{
}
else if(select==2)
{double temp;
string stemp;
for( i=0;i<c;i++){
for(j=i+1;j<c;j++){
if(std[i].ave>std[j].ave)
{
temp=std[i].ave;
std[i].ave=std[j].ave;
std[j].ave=temp;
stemp=std[i].f_name;
std[i].f_name=std[j].f_name;
std[j].f_name=stemp;
stemp=std[i].l_name;
std[i].l_name=std[j].l_name;
std[j].l_name=stemp;
stemp=std[i].f_name;
std[i].f_name=std[j].f_name;
std[j].f_name=stemp;
stemp=std[i].std_no;
std[i].std_no=std[j].std_no;
std[j].std_no=stemp;
stemp=std[i].code;
std[i].code=std[j].code;
std[j].code=stemp;
}}}
cout<<" ---sort by average--- "<<endl;
for( i=0;i<c;i++)
cout<<std[i].ave<<"\t";
cout<<endl;
}
getch();
}
- ۹۲/۱۰/۰۷
سلام خانوم علیرضایی .خیلی ممنون . درمورد اینکه گفتید قسمت عملیات ناقصه ینی من الان دقیقا باید چی کار کنم ؟؟