Hi
This is my code for submitting students
but when i use search function the course member is empty
Code:
#include "windows.h"
#include "iostream"
#include <io.h>
#include <sstream>
#include <conio.h>
#include <stdlib.h>
#include <iostream>
#define SIZE 5
using std::cout;
using std::cin;
using namespace std;
int menu();
class student {
public :
char name[20];
char family[20];
int year;
int stno;
float ave;
int id;
char namep[20];//father name
float grade[2];
char course[20];
public:
student() { name[0] = '\0';}
void enter();
int getStno() { return stno; }
void print(int &);
int search(int no);
void put();
};
//*************************
void gotoxy(int x,int y){
HANDLE hConsole;
COORD cursorLoc;
std::cout.flush();
cursorLoc.X = x;
cursorLoc.Y = y;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hConsole, cursorLoc);
}
//********************
void student::enter()
{
int i;
float sum=0;
char s[20];
system("cls");
//************sabt moshakhasat**************
cout <<"Name "<<"family "<<"course "<<"Rollno "<<"year "<<"ID "<<"Father-n"<<endl;
cin >> name;
gotoxy(8, 13);
cin >> family;
gotoxy(16, 13);
cin >> course;
gotoxy(32, 13);
cin >> stno;
gotoxy(48, 13);
cin >> year;
gotoxy(56, 13);
cin >> id;
gotoxy(64, 13);
cin >> namep;
cout<<endl;
strcpy(s,course);
//cout<<course;
cout << "please enter grade for each student:"<<endl;
if(strcmp(s,"MBA")==0){
cout <<"Physic ";
cin >>grade[0];
cout <<"Mathmatic ";
cin >>grade[1];
cout <<"Chemeist ";
cin >>grade[2];
sum=0;
for(i=0;i<3;i++){
sum=sum+grade[i];
}
ave=sum/3;}
else if(strcmp(s,"Art")==0)
{
cout <<"history ";
cin >>grade[0];
cout <<"Geography";
cin >>grade[1];
cout <<"English ";
cin >>grade[2];
sum=0;
for(i=0;i<3;i++){
sum=sum+grade[i];
}
ave=sum/3;}
else if(strcmp(s,"Sience")==0)
{
cout <<"Biology ";
cin >>grade[0];
cout <<"Mathmatic ";
cin >>grade[1];
cout <<"Chemeist ";
cin >>grade[2];
sum=0;
for(i=0;i<3;i++){
sum=sum+grade[i];
}
ave=sum/3;}
cout<<endl;
}
//*****************
void student::print(int& row)
{
cout<<row;
gotoxy(4,15);
cout << "name is:"<<name<<"\n";
cout <<"family:"<< family<<endl;
cout <<"father name:"<< namep<<endl;
cout <<"id:"<< id<<endl;
cout <<"course:"<<course<<endl;//error??????
cout <<"year:"<<year<<endl;
cout <<"Roll no:"<<stno<<endl;
cout << endl;
cout <<"\t **Result** "<<endl;
if(strcmp(course,"MBA")==0){
cout <<"Physic ";
cout<<grade[0];
cout <<"Mathmatic ";
cout<<grade[1];
cout <<"Chemeist ";
cout<<grade[2];
cout <<"\t **Result** "<<endl;
cout <<ave;
}
if(strcmp(course,"Sience")==0){
cout <<"Biology ";
cout<<grade[0];
cout <<"Mathmatic ";
cout<<grade[1];
cout <<"Chemeist ";
cout<<grade[2];
cout <<"\t **Result** "<<endl;
cout <<ave;
}
if(strcmp(course,"Art")==0){
cout <<"history ";
cout<<grade[0];
cout <<"Geography";
cout<<grade[1];
cout <<"English ";
cout<<grade[2];
cout <<"\t **moadel kol for this student** "<<endl;
cout <<ave;
}
row ++;
}
//******************
int main()
{
student *st;
int i, c,tno;
st=new student[SIZE];
for(;;) {
system("cls");
c = menu();
switch (c) {
case 1 :
cout<<"how many student you want";
cin>>tno;
for(i=1;i<=tno;i++)
st[i].enter();
break;
case 2 :
//findMax();
break;
case 3 :
// del();
break;
case 4 :
st[i].put();
cout << "\nEnter Roll no to search :";
cin>>tno;
for(int i=0;i<=SIZE;i++){
int flag=st[i].search(tno);
if(flag==1)
st[i].print(tno);
}
break;
case 5 :
exit(0) ;
} // end of switch
} //end of for(;;)
}
//*************************
int menu()
{
int c;
// system("cls");
gotoxy(5, 1);
cout << "1) Enter a student.";
gotoxy(5, 2);
cout << "2) Find best student.";
gotoxy(5, 3);
cout << "3) Delete a student.";
gotoxy(5, 4);
cout << "4) Search a student.";
gotoxy(5, 5);
cout << "5) Exit.";
do {
gotoxy(5, 7);
cout << "Enter your select(1-5) : ";
cin >> c;
} while (c < 1 && c > 5);
return c;
}
int student::search(int no)
{
int flag=0;
int i;
int tno=stno;
if(tno == no) {
return 1;
flag=1;
//std::cin.get();
}
if(flag=0) {
cout << "Student " << no << " not exist."
<< "Press a key to continue...";
std::cin.get();
return 0;
}
std::cin.get();
}
void student::put(){
cout<<course;//error
}
Thanks