.


:




:

































 

 

 

 


21

: : , , 5 . . . . . , . . . 䳿 .

:

//#include "stdafx.h"

#include <iostream>

#include <string>

#include <vector>

#include <stdio.h>

#include <conio.h>

#include <algorithm>

#include <fstream>

#define k 5 //

 

using namespace std;

using namespace System;

 

typedef struct student

{

char *name; //

int zalikovka; //

int bal[5]; //

} stud; //

 

typedef struct list{

stud std; //

struct list *next, *prev; //

} list; // '

 

void ReadStrings(char a[][40], int n); //

void Rozbuttia(char info[][40],stud a[],int n); //

list* NewElement(stud a); //

void InsertElem(list *pnew); //

void SortList(float); //

void WriteToFile(); //

void ReadFromFile(); //

 

void SortArr(int);

list *Head, *Tail; //

stud a[10];

void main()

{

int n,i,bs;

//

char info[10][40]; //

printf ("How much students add ");

scanf("%d", &n); //

fflush(stdin); //

ReadStrings(info, n); //

 

Rozbuttia(info, a, n); //

SortArr(n);

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

InsertElem(NewElement(a[i])); // '

 

WriteToFile(); //

ReadFromFile(); //

printf ("\n Input bal: ");

scanf("%d", &bs);

SortList(bs);

WriteToFile();

ReadFromFile();

putchar('\n');

system ("PAUSE"); //

}

 

 

void SortArr(int _k)

{

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

{

for(int j = 1; j < _k; j++)

{

if(strcmp(a[j-1].name,a[j].name) > 0)

{

stud _s;

_s = a[j-1];

a[j-1] = a[j];

a[j] = _s;

}

}

}

}

 

/***********************************************************************************/

/* */

/* , */

void ReadStrings(char a[][40], int n)

{

printf("Input information about Students in next format \n");

for (int i=0;i<=55;i++) putch('-');

printf("\n \Surname \Zalikova Bal[1] Bal[2] Bal[3] Bal[4] Bal[5]\"\n");

for (int i=0;i<=55;i++) putch('-');

putchar('\n');

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

gets(a[i]); //

}

/***********************************************************************************/

/* , */

/* , , */

void Rozbuttia(char info[][40],stud a[],int n)

{

int i,j;

for (i=0;i<n;i++) //

{

a[i].name=strtok(info[i]," "); //

a[i].zalikovka=atoi(strtok(NULL," ")); //

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

a[i].bal[j]=atoi(strtok(NULL," ")); //

}

}

 

/***********************************************************************************/

/* */

/* */

list* NewElement(stud a)

{

list *pel;

pel = new list; // '

pel->std=a; //

pel->next=pel->prev=NULL; //

return pel; //

}

 

/***********************************************************************************/

/* */

/* */

void InsertElem(list* pnew)

{

if (Head==NULL) //

{

pnew->next=pnew->prev=NULL; //

Head=Tail=pnew; //

}

else

{

Tail->next=pnew; //

pnew->prev=Tail; //

pnew->next=NULL; // NULL

Tail=pnew; //

};

}

 

 

/***********************************************************************************/

/* */

/* */

void SortList(float _ser)

{

list *temp=Head;

 

while (temp!=NULL) //

{

float ser=(temp->std.bal[0]+temp->std.bal[1]+temp->std.bal[2]+temp->std.bal[3]+temp->std.bal[4])/5;

if(ser < _ser)

{

 

 

if(temp->next!= NULL)

{

if(temp->prev!= NULL)

{

temp->next->prev = temp->prev;

temp->prev->next = temp->next;

}

temp->next->prev = NULL;

}

else

{

temp->prev->next = NULL;

}

 

}

 

temp = temp->next;

}

}

 

/***********************************************************************************/

/* */

/* */

void WriteToFile()

{

FILE *fp; //

char *way={"result.txt"}; //

fp=fopen(way, "a"); //

list *temp=Head; //

while (temp!=NULL) //

{

fprintf (fp, "%15s%8d%3d%3d%3d%3d%3d\n",temp->std.name, temp->std.zalikovka,

temp->std.bal[0], temp->std.bal[1], temp->std.bal[2],

temp->std.bal[3], temp->std.bal[4]); //

temp=temp->next; //

}

fprintf (fp, "%15s%8d%3d%3d%3d%3d%3d\n","-", 0,

0, 0, 0,

0, 0); //

fclose(fp); //

}

 

/***********************************************************************************/

/* */

/* */

void ReadFromFile()

{

FILE *fp; //

int i=0, ser;

char *way={"result.txt"}, temp[1][40]; // ,

stud temp1[1]; //

for (i=0;i<55;putchar('-'),i++);

printf ("\n Surname Zalikova [1] [2] [3] [4] [5] Seredne\n");

for (i=0;i<55;putchar('-'),i++);

putchar('\n');

fp=fopen(way, "r"); //

while (fgets(temp[0], 40, fp)!=NULL) //

{

Rozbuttia(temp,temp1,1); //

ser=(temp1->bal[0]+temp1->bal[1]+temp1->bal[2]+temp1->bal[3]+temp1->bal[4])/k;

printf("%15s%9d%5d%4d%4d%4d%4d%4d\n", temp1->name, temp1->zalikovka,

temp1->bal[0], temp1->bal[1], temp1->bal[2], temp1->bal[3], temp1->bal[4], ser);

ser=0;

}

}

 

 

:

void SortArr .

void ReadStrings .

void Rozbuttia - , .

list* NewElement - . .

void InsertElem - .

void ReadFromFile - . .

 

, , . , , , , ' . . ϳ , .

 

:

 

, :

 

:

 

:

 

, .

 

:

, г, 3 .

, 1995-2012

++ - , 2012, 6

 



<== | ==>
| 25 2013 N 1394
:


: 2017-02-11; !; : 349 |


:

:

: , , , , .
==> ...

1640 - | 1485 -


© 2015-2024 lektsii.org - -

: 0.026 .