السلام عليكم ورحمة الله وبركاته
كيفكم
هذا برنامج عن ادخل معلومات عن شخص وتطلب من الشخص كم رقم تلفون عنده
ودخل رقم التلفون على انه string وتضع بين ارقمين المدخله سبيس
ومن بعدها تستخدم الدوال الجاهزه لفصل ارقمين وتحويلها الى integer الارقام هذا كله عادي
وعملته
المشكله اللي صادفتني هي func tion read
اني ادخل رقم الشخص
واسمه
وعدد التلفونات
ورقم تلفونه
عملتها بس المشكله في الفيجول يقلي مايصير اعمل
cin وبعده gets
تشتغل معي شاشة الرن بس الاشياء اللي ادخالتها ب gets ماتدخل لانها قبلها cin
عرفت متغير من نوع char trash[2]
وعملت له gets قبل كل لثفس ايغى ادخلها من اول وبرضو مو راضي يزبط
فيااااااااااااااريت تساعدوني
لانه الواجب لازم اسلمه اليوم وذي المشكله اللي صادفتني لاني شغلت البرنامج على البورلند بيشتغل
وهو مطلوب منا نعمل البرنامج على فيجول سي بلس
هذا هو البرنامج
#include <ctype.h>
#include <conio.h>
#include <iostream.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
///////////////////////////////
struct customer
{
int acc_no;
char name[30];
int no_phones;
int* phones;
};
////////////////////////////////////
void read(customer* arr[10],int&n);
void token(customer* arr,int n,char ph[50]);
void disp(customer* arr[10],int n);
void del(customer* arr[10],int&n);
customer* search(customer* x,int t2);
/////////////////////////////////////////
void main()
{
int ch,n=0;
customer* arr[10];
cout<<"\n 1-Read customer";
cout<<"\n 2-Display customer";
cout<<"\n 2-Delete All Customer array ";
cout<<"\n 4-Exit";
do
{
cout<<"\nEnter number choes:";
cin>>ch;
switch(ch)
{
case 1: read(arr,n);
break;
case 2:disp(arr,n);
break;
case 3: del(arr,n);break; //put this call in exit case. Our program has 3 cases only and the delete is done when exiting.
case 4:cout<<"\n Exit";
}
}while(ch!=4);
}
/////////////////////////////////////////////////
void del(customer *arr[10],int &n)
{
for(int i=0;i<n;i++) //for loop to get each customer
{ //for(int j=0;j<arr->no_phones;j++) //for loop to get each phone no
delete arr->phones; //del the phone no
delete arr; //del the array of customer
}
cout<<"\The array of customer is deleted";
}
//////////////////////////////////////////////
void read(customer* arr[10],int&n)
{
char ph[50],trash[2]; //define string to read the phone no
arr[n]=new customer; //create new customer
cout<<"\n enter account number";
cin>>arr[n]->acc_no; //read the customer account
cout<<"\n enter name";
cin>>arr[n]->name; //read the customer name
cout<<"\n enter how many phone numbers ";
cin>>arr[n]->no_phones; //read the customer number
cout<<"\n enter number of phones ";
gets(ph); //read the customer phones number
token(arr[n],n,ph); //call token fn to break the string of phone numbers
//to different integer
n++; //add 1 to the customer counter
}
//////////////////////////////////////////////////////
void token(customer* x,int n,char ph[50])
{
char* y;int i=0; //define a char pointer and i counter
y=strtok(ph," "); //start the fn strtok to break the string if there is spaces
while(y!=NULL)
{ //wihle the string of numbers y not NULL
n=atoi(y); //convert it ti integer n using atoi
y=strtok(NULL," ");
x->phones=n; //put n in the phone integer pointer of the customer
i++; //increment i
}
}
/////////////////////////////////////////////////
customer* search(customer* x,int t2)
{
for(int h=0;h<x->no_phones;h++) //loop for all phone no for each customer
if(x->phones[h]==t2)
return x;
return NULL;
}
/////////////////////////////////////////////////
void disp(customer* arr[10],int n)
{
customer *x;
int t2;
cout<<"\n Enter phone number to search";
cin>>t2; //enter phone no to display the persone
for(int i=0;i<n;i++) //loop for all customers
{
x=search(arr,t2);
if(x!=NULL) //check if any of the phone numbers is equal to the required phone
{
cout<<"\naccount number"; //display its components
cout<<x->acc_no;
cout<<"\nname: ";
cout<<x->name;
cout<<"\nno of phones ";
cout<<x->no_phones;
for(int h=0;h<x->no_phones;h++) //dispaly all the customer phone numbers
cout<<"\nphone# "<<x->phones[h];
}
}
}
///////////////////////////////////////////////////
