السلام عليكم
أريد ان اعمل برنامج كبير شوي ، ويحتوي على الكثير من مفاهيم ال c++ ، لكن بدأت احس انه غير ممكن عمله . شرح المشروع :
عمل برنامج يتحكم في Linked list ، كل Node فيها عبارة عن class Student ، و هذه الclass هي derived من ال base class Person
بحيث اني أقوم باستخدام مفهوم File Processing وذلك بكتابة البيانات بشكل ملف Binary File او Random Access File .
البرنامج لن يحتوي على واجهه رسوميه كبداية ، بإذن بعد ان أنجز هذا الجزء سوف أقوم بمحاولة تحويله الى برنامج ذو واجهه رسومية بواسطة مكتبات MFC
سؤال اعزائي المبرمجين ، هل استمر في عمل هذا البرنامج او اتوقف لان هناك شيء ما ليس صحيحاً ؟ ( خاصة بما بتعلق بال File Processing )
هذه هي البداية فقد قمت بعمل الملفات :
Node.h
#ifndef NODE_H
#define NODE_H
#include "Student.h"
class Node
{
public:
Node( Student );
~Node();
//void updateData( Student );
Student data;
Node* next;
};
#endifNode.cpp
#include "Node.h"
Node::Node( Student stu ) : data( stu )
{
//data = newData;
next = NULL;
}
Node::~Node()
{
//data.~Student();
next = NULL;
}LinkedList.h
#ifndef LINKEDLIST_H
#define LINKEDLIST_H
#include "Node.h"
class LinkedList
{
public:
LinkedList();
~LinkedList();
void addFirst( Student );
void deleteNode();
bool isEmpty() const;
int getSize() const;
void print();
//private:
Node* firstPtr;
};
#endifLinkedList.cpp
#include "LinkedList.h"
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
LinkedList::LinkedList()
{
firstPtr = NULL;
}
LinkedList::~LinkedList()
{
firstPtr = NULL;
}
void LinkedList::addFirst( Student stu )
{
Node* newNode = new Node( stu );
if ( firstPtr != NULL )
{
newNode -> next = firstPtr;
firstPtr = newNode;
}
else
firstPtr = newNode;
}
bool LinkedList::isEmpty() const
{
return firstPtr == NULL;
}
int LinkedList::getSize() const
{
int count=0;
Node* currentPtr = firstPtr;
while ( currentPtr != NULL )
{
currentPtr = currentPtr -> next;
count++;
}
return count;
}
void LinkedList::print() const
{
Node* currentPtr = firstPtr;
if ( currentPtr != NULL )
{
while ( currentPtr != NULL )
{
cout << currentPtr -> data << endl;
currentPtr = currentPtr -> next;
}
}
else
cout <<"The list is empty.\n";
}Person.h
#ifndef PERSON_H
#define PERSON_H
#include <string>
using std::string;
class Person
{
public:
Person( int=-1, string ="" );
~person();
void setName( string );
void setID( int );
string getName();
int getID();
void print();
//private:
protected:
int id;
string name;
};
#endifPerson.cpp
#include "Person.h"
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
Person::Person( int id, string name )
{
this -> id = id;
this -> name = name;
cout <<"# Constrcutor called for " << name << endl;
}
Person::~Person()
{
cout <<"# Destrcutor called for " << name << endl;
}
void Person::setName( string name )
{
this -> name = name;
}
void Person::setID( int id )
{
this -> id = id;
}
string Person::getName()
{
return name;
}
int Person::getID()
{
return id;
}
void Person::print()
{
cout <<"Name : " << name << endl
<<"ID No : " << id << endl;
}Student.h
#ifndef STUDENT_H
#define STUDENT_H
#include "Person.h"
class Student : public Person
{
public:
Student( int=-1, string ="", int=-1, double=-1.0 );
~Student();
void setLevel( int );
void setGPA( double );
int getLevel();
double getGPA();
void print();
private:
int level;
double GPA;
};
#endifStudent.cpp
#include "Student.h"
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
Student::Student( int id, string name, int level, double GPA ) : Person( id, name )
{
this -> level = level;
this -> GPA = GPA;
cout <<"# Constrcutor called for " << name << endl;
}
Student::~Student()
{
cout <<"# Destrcutor called for " << name << endl;
}
void Student::setLevel( int level )
{
this -> level = level;
}
void Student::setGPA( double GPA )
{
this -> GPA = GPA;
}
int Student::getLevel()
{
return level;
}
double Student::getGPA()
{
return GPA;
}
void Student::print()
{
Person::print();
cout <<"Level : "<< level << endl
<<"GPA : " << GPA << endl;
}
