الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

[مساعدة] مشكلة في التعامل مع الملفات (اضافة حذف تعديل)

بدأه it.riyadh في 17 سبتمبر 2011 · 0 رد · 266 مشاهدة · في ارشيف قسم C/C++
مشاركة: واتساب X فيسبوك تيليجرام
#1

بسم الله الرحمن الرحيم

اخواني الكرام

السلام عليكم ورحمة الله وبركاته

ارجو مساعدتي في اكمال هذا البرنامج ، وهو عبارة عن ملف اقوم بما يلي

1. باضافة رقم واسم وعنوان للمستخدم (وهذه قد انتهيت منها)

2. تعديل بيانات احد الاشخاص الذين ادخلتهم ، بحيث ابحث عنه باستخدام الرقم .

3. حذف بيانات احد الاشخاص عندما اقوم بادخال رقمه.

4. البحث عن شخص معين باستخدام رقمه (وهذا قد انتهيت منه)

5. عرض كل الاشخاص الذين بالملف (وهذا قد انتهيت منه).

6. الخروج من البرنامج.

ارجو مساعدتي بهذا المشروع

وهذا هو ملف المشروع

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

#include<iostream>

#include<conio.h>

#include<fstream>

#include<process.h>

using namespace std;

fstream file("emp.txt",ios::in|ios::binary);

//int no;

struct Employee

{

int id;

char name[30], address[60];

// string id, name, address;

};

Employee Emp1;

void ReadData()

{

fstream file("emp.txt",ios::in|ios::binary);

file.read((char*)&Emp1, sizeof(Emp1));

while(!file.eof())

{

file.read((char*)&Emp1, sizeof(Emp1));

}

}

void WriteData()

{

fstream file("emp.txt",ios::out|ios::app|ios::binary);

file.write((char*)&Emp1, sizeof(Emp1));

}

bool CheckFile()

{

bool Ok = false;

if(!file)

Ok = false;

else

Ok = true;

return Ok;

}

void DisplayEmp()

{

fstream file("emp.txt",ios::in|ios::binary);

cout<<"\nID#\t\tName\t\tAddress";

cout<<"\n---\t\t----\t\t-------";

file.read((char*)&Emp1, sizeof(Emp1));

while(!file.eof() and Emp1.id!=0)

{

cout<<"\n"<<Emp1.id<<"\t\t"<<Emp1.name<<"\t\t"<<Emp1.address;

file.read((char*)&Emp1, sizeof(Emp1));

}

cout<<"\n\nPress any key to continue ... ";

getch();

}

void AddEmp()

{

cout<<"\nEmployee ID# : ";

cin>>Emp1.id;

cout<<"\nEmployee Name : ";

cin>>Emp1.name;

cout<<"\nEmployee Address : ";

cin>>Emp1.address;

WriteData();

}

void UpdateEmp(int nu)

{

}

void SearchEmp(int nu)

{

// int no;

bool found=false;

fstream file("emp.txt",ios::in);

file.read((char*)&Emp1, sizeof(Emp1));

while(!file.eof())

{

if(nu == Emp1.id)

{

found = true;

cout<<"\nID#\t\tName\t\tAddress";

cout<<"\n---\t\t----\t\t-------";

cout<<"\n"<<Emp1.id<<"\t\t"<<Emp1.name<<"\t\t"<<Emp1.address;

break;

}

else

file.read((char*)&Emp1, sizeof(Emp1));

}

if(found == false)

cout<<"\nEmployee does not found ...";

getch();

}

void DelEmp(int nu)

{

/* Wrong Code

//SearchEmp(nu);

bool found=false;

fstream file("emp.txt",ios::in);

file.read((char*)&Emp1, sizeof(Emp1));

while(!file.eof())

{

if(nu == Emp1.id)

{

found = true;

cout<<"\nID#\t\tName\t\tAddress";

cout<<"\n---\t\t----\t\t-------";

cout<<"\n"<<Emp1.id<<"\t\t"<<Emp1.name<<"\t\t"<<Emp1.address;

// Emp1.id=0;

// Emp1.name='';

// Emp1.address='';

break;

}

else

file.read((char*)&Emp1, sizeof(Emp1));

}

if(found == false)

cout<<"\nEmployee does not found ...";

getch();

*/

}

int main()

{

int sel, no;

ReadData();

if(!CheckFile())

{

cout<<"\n\n\n\n\n\n\n\n\n\t\t\tFile does not found !!!";

goto Exit;

}

else

do{

system("cls");

cout<<"\n\n\n\n\t\t\t==========================";

cout<<"\n\t\t\t= 1. Add Employee =";

cout<<"\n\t\t\t= 2. Update Employee =";

cout<<"\n\t\t\t= 3. Delete Employee =";

cout<<"\n\t\t\t= 4. Search for Employee =";

cout<<"\n\t\t\t= 5. Display Employee =";

cout<<"\n\t\t\t= 0. Exit =";

cout<<"\n\t\t\t==========================";

cout<<"\n\n\t\t\tEnter your Choice : ";

cin>>sel;

switch(sel)

{

case 1:

AddEmp();

break;

case 2:

cout<<"\nEnter the Employee ID# : ";

cin>>no;

UpdateEmp(no);

break;

case 3:

cout<<"\nEnter the Employee ID# : ";

cin>>no;

DelEmp(no);

break;

case 4:

cout<<"\nEnter the Employee ID# : ";

cin>>no;

SearchEmp(no);

break;

case 5:

DisplayEmp();

break;

case 0:

exit(0);

break;

default:

system("cls");

}

}while(sel != 0);

Exit:

getch();

return 0;

}

بإنتظار مساعدتكم الكريمة ,,,, والعاجلة

c++.txt

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…