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

ممكن مساعده!

مغلق
بدأه زهره في 13 أغسطس 2003 · 8 رد · 673 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

مرحبا!..

هذا اسايمنت.. طلع روحنا.. يصير تساعدونا فيه!

السؤال هني!

http://arwaa.jeeran.com/2.gif

السؤال الاول حاونا نحله بهذي الطريقه ..

#include
void main ()
{
FILE *cfptr;
FILE *cfptr2;
char x;



	cfptr2=fopen ("Fatima#1.cpp","w");
if ((cfptr= fopen("Fatima#2.cpp","r"))==NULL)
	printf("File could not be openedn");
else
  {
	  while (!feof(cfptr))
		 {
			  x=fgetc(cfptr);
					if (x=='/')
			  {
				x=fgetc(cfptr);
				if(x=='*')
				  {
			 x=fgetc(cfptr);
				 while (x!='*')
					 {
					  x=fgetc(cfptr);
					 }
continue;
				  }
				}
fprintf(cfptr2,"%c",x);
	   }
	fclose(cfptr);
	fclose(cfptr2);
	}
}
#2

#include

#define size 100

int a[size],b[size];

struct Tool

{

int toolnum;

char toolname[20];

int quantity;

float cost;

};

typedef struct Tool tool; // You dont really need a typedef here!

// it is USELESS!

struct date

{

int day;

char month[20];

int year;

};

typedef struct date Date;

int binarySearch(int d[], int s, int item)

{

int loc=-1, low=0, high=s-1 , midpt;

while(low

{

midpt=(low+high)/2;

if(item==d[midpt])

loc=midpt;

else if(item

high=midpt-1;

else

low=midpt+1;

}

return(loc);

}

void IndexFile(FILE *fptr,FILE *index)

{

if ((fptr=fopen("hardware.dat","a+"))==NULL)

printf ("File could not be opened");

else

{

for (int i=0; i<100; i++)

fwrite(&index,sizeof (Tool),1,fptr);

}

fclose(fptr);

}

void NewTool(FILE *fptr,int c[])

{

int location;

//Tool tool={0,"",0,0.0,0-0-0,NULL}; WRONG!

// to define a structure use something similar to the below:

tool test={0,"",0,0.0};

Date one;

printf("Enter new tool number:n");

scanf("%d",&test.toolnum);

location=binarySearch(c,size,test.toolnum);

if (location!=-1)

printf("Tool # %d already contains information",test.toolnum);

else

{

printf("Enter the tool name:n");

scanf("%c",&test.toolname);

printf("Enter quantity:n");

scanf("%d",&test.quantity);

printf("Enter cost:n");

scanf("%f",&test.cost);

printf("Enter date:n");

scanf("%d %d %d",&one.day,&one.month,&one.year);

fseek(fptr,(test.toolnum-1)*sizeof(test),SEEK_SET);

fwrite(&test,sizeof(tool),1,fptr);

}

}

void UpdateQuantityI(FILE *fptr,int c[])

{

int location;

int iord;

tool test={0,"",0,0.0}; // there are three member types only!

double update;

printf("Enter tool number that you want to update:n");

scanf("%d",&test.toolnum);

location=binarySearch(c,size,test.toolnum);

if(c[location]==-1)

printf("Tool # %d has no informationn",test.toolnum);

else

{

printf("Enter 1 to increase & 2 to decrease:n");

// scanf("%d",&test.iord); what is iord??!

if (test.iord==1) // what is iord?

{ // dont forget the brackets!

test.balance+=test.quantity; // there is no varaible named as balance

// in the structures!

fseek(fptr,(test.toolnum-1)*sizeof(tool),SEEK_SET);

fwrite(&test,sizeof(tool),1,fptr);

pirntf("%d",test.balance); // printf NOT pirntf!!

scanf("%d",&test.balance);

}

else if (iord==2) // Iord again?!

{

test.balance-=test.quantity;

fseek(fptr,b[location],SEEK_SET);

fwrite(&test,sizeof(tool),1,fptr);

printf("%d",test.balance);

scanf("%d",test.balance);

}

}

}

void UpdatePricedate(FILE *fptr, int c[])

{

float nprice;

Date d;

tool test;

printf("Enter the new price:n");

scanf("%f",&test.price); // There is no Price in the structure!

printf("Enter the date:n");

scanf("%d %d %d",&d.day,&d.month,&d.year);

fseek(fptr(test.toolnum-1)*sizeof(tool),SEEK_SET); // where did the toolnum came from?

fread(&tool,sizeof(tool),1,fptr); // No structure is defined to read from!

test.price=test.price;

fseek(fptr(toolnum-1)*sizeof(tool),SEEK_SET);

fread(&test,sizeof(Tool),1,fptr); //you passed wrong paramenters!

}

void PrintTool(FILE *fptr,int c[])

{

int location;

//Tool tool={0,"",0,0.0,0-0-0,NULL}; WRONG!

tool test={0,"",0,0.0};

printf("Enter tool no. that you wish to print details of itn");

scanf("%d",&test.toolnum);

location=binarySearch(c,size,test.toolnum);

if(c[location]==-1)

printf("Tool # %d has no informationn",Tool.toolnum);

else

{

fseek(fptr,b[location],SEEK_SET);

printf("Tool Number = %dnTool Name is: %cnQuantity = %dnCost = %fn",Tool.toolnum,Tool.name,Tool.quantity,Tool.cost);

}

}

void PrintAll(File *fptr,int c[])

{

//Tool tool={0,"",0,0.0,0-0-0,NULL}; WRONG!

tool test={0,"",0,0.0};

for (int i=0;i !=feof , i++)

{

printf("Tool Number = %dnTool Name is: %cnQuantity = %dnCost = %fn",test.toolnum,test.name,test.quantity,test.cost);

}

}

void DeleteTool(FILE *fptr,FILE *index,int c[])

{

int location;

//Tool tool; Wrong! tool is a typedef!

tool test;

tool deletetool={0,"",0,0.0,0-0-0,NULL};

printf("Enter tool no. to delete:n");

scanf("%d",&test.toolnum); // No structure is declared!

location=binarySearch(c,size,tool.num);

if (location==-1)

printf("Tool # %d does not exist.",tool.toolnum);

else

{

fseek(fptr,b[location],SEEK_SET);

fwrite(&deletetool,b[location],1,fptr);

}

blank(fptr,blank);

}

void main()

{

FILE *fptr;

FILE *index;

int choice;

index=fopen("C:/hardware.dat","r");

if((fptr=fopen("C:/hardware.dat","a+"))==NULL)

printf("File does not exist");

else

{

printf("Enter your choicen 1:Add new tool to filen 2:Update the qantityn 3:Update the price & daten"

"4:Print details of a specific tooln 5:Print details of all toolsn 6:Delete a tooln 7:Endn");

scanf("%d",&choice);

while((choice>0)&&(choice:(!

#3

اجابة السؤال الأول

#include
void main ()
{
FILE *cfptr;
FILE *cfptr2;
char x;
char y;
char z;
int comments=0;
int cancel=0;

    cfptr2=fopen ("test2.cpp","w");
if ((cfptr= fopen("test.cpp","r"))==NULL)
    printf("File could not be openedn");
else
  {
      while (!feof(cfptr))
         {
              x=fgetc(cfptr);
			  comments=0;

              if (x=='/')
              {
                y=fgetc(cfptr);
				if(y=='*'||y=='/')
						comments=1;
                if(y=='*')
                  {				
					do
					{
					    cancel=0;
						y=fgetc(cfptr);
				      z=fgetc(cfptr); 
					  if((y=='*')&&(z=='/'))
							cancel=1;
					}
					while (!cancel);
                  }
					else
						if(y=='/')
				    		do
							{
								z=fgetc(cfptr);


							}
							while ((z!='n')&&(z!='r'));

                }
			  if(!comments)
					fprintf(cfptr2,"%c",x);
       }
    fclose(cfptr);
    fclose(cfptr2);
    }
}
اللهم انا نسألك علما نافعا ونعوذ بك من حماقة الجهلاء
#4

khwlani... شكرا جزيلا على المساعده..:)

والسؤال الثاني.. تكفوووووون :'(

#5

والحل.. :(

محد ناوي يساعد :(

بلييييييييييييييييز:'(

#6

حاولي شرح المشكلة بالعربي ماهو المطلوب وماذا تكون نتائج برنامجك حتى استطيع ان اساعدك

اللهم انا نسألك علما نافعا ونعوذ بك من حماقة الجهلاء
#7

شكرا khwlani على الاهتمام :)..

امس قدمنا امتحان الماده هذي.. دعواتكم ان شاء الله ناخذ درجات زينه :)..

وجهزوا روحكم بنأذيكم في الديتا ستركجر:o

#8

ان شاء الله بالتوفيق

اللهم انا نسألك علما نافعا ونعوذ بك من حماقة الجهلاء
#9

ممكن تكتب بطريقه الكود لكي يكون اوضح ويسهل الرد عليه[main()]

هذا الموضوع مغلق.

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