Çevrimdışı
Kullanıcıların profil bilgileri misafirlere kapatılmıştır.
| Cevap: Örnek Kodlamalar Buraya..
Klasik Öğrenci Kayıt Sistemi
C++ dersini aldığımda verilmiş bir proje idi. Bilg. Mühd. öğrencilerine genellikle verilen fix projelerden biridir. Kod: Kodu kopyalamak için üzerine çift tıklayın! #include <iostream>
#include <fstream>
#include <string>
#include <cctype>
using namespace std;
class StudentList;
class StudentList
{
private:
struct node
{
int StudentId;
string StudentSurname;
string StudentName;
string Department;
node *IdNext;
node *SurnameNext;
};
public:
StudentList();
~StudentList();
void add(node n);
void pSurname(); //List w.r.t Surname
void pId(); //List w.r.t ID
bool del(int id);
friend void createStudentList(string fileName,StudentList&);
node *First,*FirstSurname;
friend void editStudentList(StudentList & listName);
};
string CutPart(int First,int last,string line);
string _ToUpper(string s); Kod: Kodu kopyalamak için üzerine çift tıklayın!
#include "project2.h"
#define sizeOfLine 1000
#include <algorithm>
#include <sstream>
#define PrintWrtSurname "ps"
#define PrintWrtId "pi"
#define AddStudent "i"
#define DeleteStudent "d"
#define Quit "q"
StudentList::StudentList()
{
First = NULL;
FirstSurname = NULL;
}
StudentList::~StudentList()
{
node *temp,*q;
if ( First==NULL)
return;
temp = First;
if (temp->IdNext == First)
{
delete temp;
return;
}
while ( temp->IdNext != First)
{
q= temp;
temp = temp->IdNext;
delete q;
}
delete temp;
}
void editStudentList(StudentList &List)
{
string command;
cout << "Welcome to Student Registration System " << endl;
for(;;){
cout << "Enter a command: ";
cin >> command;
if(command == PrintWrtSurname){
List.pSurname();
cout << "With respect to surname" << endl;
}
else if(command == PrintWrtId){
List.pId();
cout << "With respect to id" << endl;}
else if (command == Quit){
break;
cout << "DONE" << endl;
return;
}
else if (command ==AddStudent){
string t;
int num;
StudentList::node temp;
cout << "Enter idno:";
cin >> t;
temp.StudentId = atoi(t.c_str());
cout << "Enter Surname:";
cin >> t;
temp.StudentSurname = _ToUpper(t);
cout <<"Enter Name:";
cin >> t;
temp.StudentName = _ToUpper(t);
cout << "Enter Department:";
cin >> t;
temp.Department = _ToUpper(t);
List.add(temp);
}
else if (command == DeleteStudent){
unsigned int num;
StudentList::node temp;
cout << "Enter idno:";
cin >> num;
List.del(num);
}
else cout << "No Command:" << command << endl;
}
}
string _ToUpper(string str)
{
for (int i = 0; i < str.length(); i++)
{
str[i]=toupper(str[i]);
}
return str;
}
void StudentList::add(node n)
{
node *temp,*t,*k;
t = new node;
t->StudentId = n.StudentId;
t->StudentName = n.StudentName;
t->StudentSurname =n.StudentSurname;
t->Department = n.Department;
if ( First == NULL)
{
t->IdNext = t;
t->SurnameNext = t;
First = t;
FirstSurname = t;
return;
}
for ( k= First; k->IdNext !=First; k= k->IdNext)
{
if (k->StudentId == t->StudentId)
{
cout << "StudentID is unique";
return;
}
}
if ( k->StudentId == t->StudentId) {
cout << "StudentID is unique";
return;
}
// In the List, there is one element
if (First->IdNext == First)
{
First->IdNext = t;
t->IdNext = First;
if (First->StudentId > t->StudentId){
First = t;
}
// Changing Surname
FirstSurname->SurnameNext = t;
t->SurnameNext = FirstSurname;
if (FirstSurname->StudentSurname > t->StudentSurname){
FirstSurname = t;
}
}
else
{
temp = FirstSurname;
// Begining of the Surname List, there may be add new node
if (t->StudentSurname < FirstSurname->StudentSurname) {
t->SurnameNext = FirstSurname;
// Last Node
while ( temp->SurnameNext != FirstSurname) { temp= temp->SurnameNext;}
temp->SurnameNext = t;
t->SurnameNext = FirstSurname;
FirstSurname = t;
}
else {
while ( temp->SurnameNext != FirstSurname) {
if ((temp->SurnameNext)->StudentSurname > t->StudentSurname) {
t->SurnameNext = (temp->SurnameNext);
temp->SurnameNext = t;
break;
}
temp = temp->SurnameNext;
}
// At the end of the list, there may be added
if ( temp->SurnameNext == FirstSurname) {
temp->SurnameNext = t;
t->SurnameNext = FirstSurname;
}
}
temp = First;
//If new node is added begining of the ID Number List
if (t->StudentId < First->StudentId){
// Last of List
while ( temp->IdNext != First){temp=temp->IdNext;}
temp->IdNext = t;
t->IdNext = First;
First = t;
}
// Added element to the List
else
{
while (temp->IdNext != First){
if ( (temp->IdNext)->StudentId > t->StudentId){
t->IdNext = (temp->IdNext);
temp->IdNext = t;
break;
}
temp= temp->IdNext;
}
if( temp->IdNext ==First){
temp->IdNext = t;
t->IdNext = First;
}
}
}
}
bool StudentList::del(int id)
{
node *temp,*i, *tempSur, *j,*lastSurname;
if ( First== NULL){
cout << "Empty List";
return false;
}
else if ( First->IdNext == First)
{
if(First->StudentId == id){
delete First;
First = NULL;
FirstSurname =NULL;
return true;
}
return false;
}
else {
temp = First;
i= First;
j= FirstSurname;
while ( temp->StudentId != id) { temp = temp->IdNext;}
while ( i->IdNext != temp){ i= i->IdNext;}
// i is a node
i->IdNext = temp->IdNext;
if ( temp == First) {First = temp->IdNext;}
// Next Surname
while (j->SurnameNext != temp) {j = j->SurnameNext;}
// j points to a node in Surname List
j->SurnameNext = temp->SurnameNext;
if ( temp == FirstSurname ) {FirstSurname = temp->SurnameNext;}
delete temp;
}
}
void StudentList::pId()
{
node *temp;
temp= First;
if(First==NULL)
{
cout << "Empty List";
return;
}
else if ( temp->IdNext == First){
cout << First->StudentId <<", "<<First->StudentName<<", "<<
First->StudentSurname<< ", "<< First->Department;
return;
}
else {
while (temp->IdNext != First){
cout << temp->StudentId <<", "<<temp->StudentName<<", "<<
temp->StudentSurname<< ", "<< temp->Department<<endl;
temp = temp->IdNext;
}
cout << temp->StudentId <<", "<<temp->StudentName<<", "<<
temp->StudentSurname<< ", "<< temp->Department<<endl;
}
}
void StudentList::pSurname()
{
node *temp;
temp= FirstSurname;
if(FirstSurname==NULL)
{
cout << "The List is empty";
return;
}
else if ( temp->SurnameNext == FirstSurname)
{
cout << FirstSurname->StudentSurname <<", "<<FirstSurname->StudentName<<", "<<
FirstSurname->StudentId<< ", "<< FirstSurname->Department;
return;
}
else
{
while (temp->SurnameNext != FirstSurname)
{
cout << temp->StudentSurname <<", "<<temp->StudentName<<", "<<
temp->StudentId << ", "<< temp->Department<<endl;
temp = temp->SurnameNext;
}
cout << temp->StudentSurname <<", "<<temp->StudentName<<", "<<
temp->StudentId<< ", "<< temp->Department<<endl;
}
}
void createStudentList(string fileName,StudentList &List){
char line[500];
int pivot1,pivot2,count=1,idNum,recordNum=0;
string temp,aline,name,surname,department;
ifstream ListFile (fileName.c_str());
// End of the Line
while (! ListFile.eof() )
{
recordNum++;
ListFile.getline (line,500);
aline=line;
pivot1=pivot2=0;
count=1;
// A Line
for(unsigned int i=0;i<(aline.length());i++)
{
if(line[i]==','&& count==1)
{
pivot2=i;
temp=CutPart(pivot1,pivot2,aline);
count++;
pivot1=i;
idNum= atoi(temp.c_str());
}
else if(line[i]==',' && count==2)
{
pivot2=i;
temp=CutPart(pivot1+1,pivot2,aline);
count++;
pivot1=i;
name= temp;
}
else if(line[i]==',' && count==3)
{
pivot2=i;
temp=CutPart(pivot1+1,pivot2,aline);
count++;
pivot1=i;
surname= temp;
pivot2=aline.length();
temp=CutPart(pivot1+1,pivot2,aline);
department=temp;
}
}
if(count!=4)
{
cout <<"Invalid record in file at "<<recordNum<<"th(nd) row";
}
else
{
StudentList::node temp;
temp.StudentId = idNum;
temp.StudentName = name;
temp.StudentSurname = surname;
temp.Department = department;
List.add(temp);
}
}
ListFile.close();
}
string& trim(string &str)
{
int i,j,start,end;
//left trim
for (i=0; (str[i]!=0 && str[i]<=32); )
i++;
start=i;
//right trim
for(i=0,j=0; str[i]!=0; i++)
j = ((str[i]<=32)? j+1 : 0);
end=i-j;
str = str.substr(start,end-start);
return str;
}
string& ltrim(string &str)
{
int i,start;
for (i=0; (str[i]!=0 && str[i]<=32); )
i++;
start=i;
str = str.substr(start,str.length()-start);
return str;
}
string& rtrim(string &str)
{
int i,j,end;
for(i=0,j=0; str[i]!=0; i++)
j = ((str[i]<=32)? j+1 : 0);
end=i-j;
str = str.substr(0,end);
return str;
}
string CutPart(int First,int last,string line)
{
string temp;
if(First<0 && First>line.length() && last>line.length() && First>last) return temp;
for(int i=First;i<last;i++)
{
temp+= line[i];
}
return trim(temp);
} Kod: Kodu kopyalamak için üzerine çift tıklayın! #include "project2.h"
int main()
{
StudentList x;
createStudentList("StudentList.txt",x);
editStudentList(x);
for(;;);
} Kod: Kodu kopyalamak için üzerine çift tıklayın! #include <iostream>
#include <string>
#include <stack>
#include <cctype>
using namespace std;
// The following defns should go into a .h file
#define PrintWrtSurname "ps"
#define PrintWrtId "pi"
#define AddStudent "i"
#define DeleteStudent "d"
void editStudentList(/* StudentList&*/)
{
string command;
cout << "Welcome to Student Registration System " << endl;
for(;;){
cout << "Enter a command: " << endl;
cin >> command;
if(command == PrintWrtSurname){
// StudentList.printwrtSurname(); //
cout << "List with respect to surname" << endl;}
else if(command == PrintWrtId){
// StudentList.printwrtId(); //
cout << "List with respect to id" << endl;}
else if (command == Quit){
cout << "DONE " << endl;
return;}
else cout << "NO command: " << command << endl;
}
}
int main(){
editStudentList(/* cmpe160 */);
return 0;
} Kod: Kodu kopyalamak için üzerine çift tıklayın! 2007100307, OGUZ ,CEYLAN , cet
2005100700, HASAN , COSKUN , tt
2008400024,DUYGU ,ALGAN , cmpe
2007101336, BETUL ,ARI ,cmpe
2006104564,ERCAN , AY , ee
2008400180, ERVIN ,DOMAZET,man
2004102743,AHMET FAIK, BAK , cmpe
2007100631, EMRECAN ,BATI ,cee
2004104291, TURGAY, CAN , cmpe
2003104024,ERSIN, AYDIN , ee
2006104624,AHMET , AYDIN , cmpe
2008400033, HAKAN , DEMIR , man
2007100625, ENES BAHADIR , DISBUDAK , man
2003104471,HASAN,ELMAS,man
2007102347,ESRA ,ARSLAN ,cmpe
2005100736,REMZI ,ASCI ,ee
2006102371, BULUT ,DEMIR , ptw |