PDA

View Full Version : سوال: کمک در رابطه با اضافه کردن - حذف و جستجو با لیست پیوندی



jaafar1363
شنبه 10 اردیبهشت 1390, 08:51 صبح
سلام بچه ها
این برنامه ساده ایه که قابلیت اضافه و حذف و جستجوی دانشجو رو داره.
می خوام بدونم که چرا :
1.عبارت goto(x,y) کار نمی کند.بهمین خاطر برای قسمت جستجوی دانشجو ، نام و فامیل و شماره شناسایی دانشجو دقیقا زیر همان فیلد قرار نمی گیرد.مشکل چیه؟
2.من می خوام قبل این برنامه یه منویی داشته باشه که:
شامل 4 دانشکده باشد:
1.برق
2.کامپیوتر
3.ریاضی
4.مکانیک
که با زدن مثلا دکمه *1.برق * برنامه من اجرا بشه.
--------------------------------------------------------------
اضافه و حذف و جستجوی دانشجو برای 4 دانشکده
--------------------------------------------------------------
برنامه من----->


#include <iostream>
using std::cout;
using std::cin;
#include <conio.h>
#include<string>
typedef struct MyStudent
{
char FName[50],LName[50];
long StudentNumber;
char Status;
}Student;
Student st[100];
int cnt=0;
long STDNum; //Student Number
char FirstName [50], LastName[50];
char Status;
void Title();
void ShowMenu();
int Item_Select();
int Search(long num);
void Add_Student();
void Del();
void Searching();
int Exit();
int ReadKey=0;
void main()
{

switch(Item_Select()){
case 1:Add_Student(); break;
case 2:Del(); break;
case 3:Searching(); break;
case 4:Exit(); break;
}//end of switch
}
int Item_Select()
{
ShowMenu();
cin >> ReadKey;
if (ReadKey>=1 || ReadKey<=6)
return ReadKey;
return -1;
}
void Title()
{
//clrscr();
cout << "\t\t\t" << " College Managment" << "\n\n";
cout << "\t\t\t" << " Programmer: Shahabi far && Cheraghiyan" << "\n\n";
cout << "\n\n\n\n";
}
void ShowMenu()
{
//clrscr();
Title();
cout <<"\t" << "Select one of the items:" << "\n\n";
cout << "\t" <<"========================" << "\n\n\n";
cout << "\t" << "1- Add New Student in Class" << "\n\n\n";
cout << "\t" << "2- Delete Student" << "\n\n\n";
cout << "\t" << "3- Search Student" << "\n\n\n";
cout << "\t" << "4- Exit to program" << "\n\n\n";


}
void Add_Student()
{
// clrscr();
if (cnt<100)
{
cout << "\t\t\t" << "Add New Student";
cout << "\n\n\n" << "Please Enter Student Number:" << "\t";
cin >> STDNum;
if (Search(STDNum)==-1)
{
//First Name
cout << "\n\n" << "Please enter First Name of this student:" << "\t";
cin >> FirstName;
//Last Name
cout << "\n\n" << "Please enter Last Name of this student:" << "\t";
cin >> LastName;
Status='N';
for (int i=0;i<50;i++)
{
st[cnt].FName[i]=FirstName[i];
st[cnt].LName[i]=LastName[i];
}//end of for
st[cnt].StudentNumber=STDNum;
st[cnt].Status='N';
}//end of second if
else
cout <<"You can not Add this student, This student is register.";
cnt++;
main();
}//end of first if
}
void Del()
{
// clrscr();
cout << "\t\t\t" << "Delete Student";
cout << "\n\n" << "Students of this class are:";
for (int i=0;i<100;i++)
{
if (st[i].StudentNumber!=0 && st[i].Status=='N')
{
cout << "\n" << st[i].StudentNumber << "\t";
cout << st[i].FName << "\t";
cout << st[i].LName;
}//end of if
}//end of for
cout << "\n\n\n" << "Enter Student Number:" << "\t";
cin >> STDNum;
int index=Search(STDNum);
if (index!=-1)
{st[index].Status='D'; //Status is delete
cout << "\n\n" << "this student will be remove";}
else
cout << "\n\n\n" << "this student not found!";
cout << "\n\n\n\n" << "Press a key to back main menu";
getch();
main();
}
void Searching()
{
// clrscr();
cout << "\t\t\t" << "Search Student";
cout << "\n\n\n" << "Student of this class are:";
for (int i=0;i<100;i++)
{
if (st[i].StudentNumber!=0)
{
cout << "\n" << st[i].StudentNumber << "\t";
cout << st[i].FName << "\t";
cout << st[i].LName;
}//end of if
}//end of for
cout << "\n" << "------------------------------";
cout << "\n" << "Enter Student Number:" << "\t";
cin >> STDNum;
int index=Search(STDNum);
if (index!=-1)
{
int x=10,y=1; //for gotoxy(y,x)
cout << "\n\n\n" << " FName LName Student Number ";
cout << "\n" << "---------- ---------- ------------------ ";
cout << "\n\n";
cout << st[index].FName;
// gotoxy(y+13,x);
cout << st[index].LName;
// gotoxy(y+31,x);
cout << st[index].StudentNumber;
}
else
cout << "\n\n" << "This student not register!";

cout << "\n\n\n\n\n" << "Press any key to back main menu";
getch();
main();

}
int Search(long num)
{
for (int i=0;i<100;i++)
if (num==st[i].StudentNumber)
return i;
return -1;
}
int Exit()
{
return 0;
}

r00tkit
شنبه 10 اردیبهشت 1390, 09:16 صبح
goto(x,y)
دیگه نداریم
http://www.google.com/search?hl=en&client=firefox-a&hs=WK3&rls=org.mozilla%3Aen-US%3Aofficial&q=gotoxy+in+windows&aq=f&aqi=&aql=&oq=