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

قراءه من فايل (احد يشيك لي ع الحل)

بدأه خوله88 في 27 سبتمبر 2008 · 1 رد · 495 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

المساله :

write a simple directory program that looks up phone numbers in a file

containing a list of names and phone numbers .The user prompted to enter

a first and last name and the program outputs the corresponding number

or indicates the the name is not in directory.

After each look up,the program should ask the user whether they wantto look up

another number,and then either rpeat the process or exist th program.

the data on the file should organized so that each line contain

a first name ,last name , and phone numbers .

#include<iostream>

#include<fstream>

#include<string>

using namespace std;

int main()

{

string first,last;

string fname,lname;

string filename;

ifstream infile;

int phone;

infile.open("phone.txt");

if (!infile)

{

cout<<"Can't open file phone.txt"<<endl;

return 1;

}

if(infile)

cout<<"please enter your first and last name"<<endl;

cin>>first>>last;

{

infile>>fname>>lname>>phone;

cout<<endl;

if(infile)

{

fname=first;

lname=last;

cout<< phone<<endl;

}

else

cout<<"your name is not in directory"<<endl;

cout<<endl;

cout<<"please enter other name"<< endl;

cin>>first>>last;

if(infile)

{

fname=first;

lname=last;

cout<< phone<<endl;

}

}

cout<<endl;

infile.close();

return 0;

}

#2

السلام عليكم وكل عام وانتي بخير

بس لو كان الكود ارتب شوي كان صار اسهل تعقبه..

البرنامج شغال بس كان ناقصه بعض التعديلات... ارجو الإفادة لك..

وهي البرنامج..


#include<fstream>
#include<string>

using namespace std;

int main()
{
string first,last;
string fname="_";
string lname="_";
string filename;
ifstream infile;
int phone;

infile.open("phone.txt");
if (!infile)
{
cout<<"Can't open file phone.txt" << endl;
return 1;
}

if(infile)
cout<<"please enter your first and last name" << endl;

cin >> first >> last;

while ((fname!=first) && (lname!=last))
infile >> fname >> lname >> phone;

cout << endl;
if((first == fname) && (last == lname))
cout << phone << endl;

else
cout << "your name is not in directory"<<endl;

cout << endl;
infile.close();
return 0;
}
 #include<iostream>

تحياتي

فارس

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