.


:




:

































 

 

 

 


( )


 

 

VI


 

 

: ..

: 08-105, 12 .

: ..

 

 

 

2012

 

.

, (15-20).

2-3 p .

, , UNIX. argc argv.

.

(34 ):

, p .

 

1) . :

) ,

)

)

)

)

)
)

OC UNIX -.

2) .

out.dat. . , .

 

3) .

 

4) printf() scanf() p.

 

5) if{} p . p, (, - , ..)

: Ubuntu 10.04 LTS Lucid Lynx

: C++

: /home/ kp6

:

g++ 6kp.cpp o 6kp.exe

./ 6kp.exe list1

 

 

 

, , , , , . -, , . -, . , . , .

 

 

 

1. struct {.}; :

 

name char
numberofthings int -
weightofthing float
destination char
time float (.)
transplantation char
children char

 

1) generation.c:

value.h :

:

void write_student(FILE* out, student s) , (08-105, 08-106, 08-108) . out.

int information_about_student(FILE* list, student* s) , , , , , , .

int main() , .

2) rabota.c:

int TR(student s) , , . q, 1, , .

int read_student(FILE* list, student* s) - , , .

int main(int a, char b*[c]) -, . , . , , .

 

List 1:

_.. 6 220 - 12.50

_.. 5 200 16.30

_.. 3 185 14.27

_.. 7 278 15.40

_.. 5 200 13.40

_.. 4 190 19.50

_.. 7 270 20.40

_. 3 9 250 20.08

_.. 1 90 12.30

_.. 2 135 05.30

List 2:

_.. 3 145 09.48

_.. 4 170 10.45

_.. 5 167 07.26

_.. 1 89 08.40

_.. 2 78 13.50

_.. 4 146 15.40

_.. 6 127 17.35

_.. 5 176 18.35

_.. 8 198 17.29

_.. 9 200 19.40

List 3:

_.. 3 156 17.38

_.. 4 163 21.48

_.. 5 153 22.58

_.. 2 143 17.36

_.. 6 148 14.38

_.. 9 207 22.44

_.. 10 237 23.56

_.. 7 145 14.48

_.. 6 164 23.45

_.. 5 193 14.37

 

#include<stdio.h>

#include<string.h>

 

int main(int argc, char*argv[])

{

 

FILE *f,*g;

struct

{ char name[30];

int numberofthings;

float weightofthing;

char destination[30];

float time;

char transplantation[10];

char children[10];

 

} s;

 

int l,i,j=0,k=0; int p;

if((f=fopen(argv[1],"r"))==NULL)

printf("Can't open input file\n");

if((g=fopen("out.dat","w+"))==NULL)

printf("Can't open output file\n");

l=sizeof(s); // printf("\nl=%d\n",l);

 

printf(" \n");

printf("______________________________________________\n");

printf("| | - | | - | | | |\n");

printf("|_______________|_______________|_______________|_______________|____________|__________________|_____________|\n");

while (!feof(f))

{

fscanf(f,"%s", s.name);

fscanf(f,"%d", &s.numberofthings);

fscanf(f,"%f", &s.weightofthing);

fscanf(f,"%s", s.destination);

fscanf(f,"%f", &s.time);

fscanf(f,"%s", s.transplantation);

fscanf(f,"%s", s.children);

if(feof(f)) break;

 

printf("|%-15s\t",s.name);

printf("|\t %d \t",s.numberofthings);

printf("| %.1f \t",s.weightofthing);

printf("|%-15s \t",s.destination);

printf("| %.2f\t ",s.time);

printf("| %-5s\t",s.transplantation);

printf("| %-6s\t |\n",s.children);

printf("|_______________|_______________|_______________|_______________|____________|__________________|_____________|\n");

 

fwrite(&s,l,1,g);

k++;

}

printf("k=%d\n",k);

 

rewind(g);

 

printf(" p:\n");

scanf("%d",&p);

printf("\n , , %d \n",p);

printf("______________________________________________\n");

printf("| | - | | - | | | |\n");

printf("|_______________|_______________|_______________|_______________|____________|__________________|_____________|\n");

 

for(i=0; i<k; i++)

{

fread(&s,l,1,g);

 

//printf("%s",s.name); printf("%d",s.numberofthings);

 

if(s.numberofthings > p)

{

printf("|%-15s\t",s.name);

printf("|\t %d \t",s.numberofthings);

printf("| %.1f \t",s.weightofthing);

printf("|%-15s \t",s.destination);

printf("| %.2f\t ",s.time);

printf("| %-5s\t",s.transplantation);

printf("| %-6s\t |\n",s.children);

printf("|_______________|_______________|_______________|_______________|____________|__________________|_____________|\n");

}

 

}

if(i==0){

printf(" , %d \n",p);}

 

fclose(f);

fclose(g);

 

}

-
1. . 29.04 16.00   , .    
  02.05 18.30 if(i=0)    

, . , , , . . . , . , .



<== | ==>
1. |
:


: 2016-12-18; !; : 980 |


:

:

, .
==> ...

1608 - | 1402 -


© 2015-2024 lektsii.org - -

: 0.039 .