Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "student.h"
- #define LEN 1000
- int student::init (const char *n,int v)
- {
- value=v;
- if(n)
- {
- name = new char[strlen(n)+1];
- if(!name) return -1;
- strcpy(name,n);
- return 0;
- }
- name=0;
- return 0;
- }
- student::student(const char *n,int v)
- {
- init(n,v);
- }
- student::student(const student &x)
- {
- init (x.name,x.value);
- }
- student::~student()
- {
- if(name)
- {
- delete[]name;
- name=0;
- }
- value=0;
- }
- student & student:: operator=(const student &x)
- {
- this -> ~student();
- init(x.name,x.value);
- return *this;
- }
- int student :: operator < (const student & b)
- {
- if (strcmp(name,b.name)<0) return 1;
- else
- {
- if (strcmp(name,b.name)==0)
- {
- if (value<b.value) return 1;
- }
- }
- return 0;
- }
- int student :: operator > (const student & b)
- {
- if (strcmp(name,b.name)>0) return 1;
- else
- {
- if (strcmp(name,b.name)==0)
- {
- if (value>b.value) return 1;
- }
- }
- return 0;
- }
- int student :: operator == (const student & b)
- {
- if (strcmp(name,b.name)==0 && value==b.value) return 1;
- return 0;
- }
- int student:: read(FILE *fp)
- {
- char buf[LEN];
- this -> ~student();
- if(fscanf(fp,"%s%d",buf,&value)!=2)
- {
- if(feof(fp)) return -1;
- return -2;
- }
- return init (buf,value);
- }
- void student:: print(FILE *fp,int level)
- {
- int j;
- for(j=0;j<level*2;j++) printf(" ");
- fprintf(fp,"%s-%d\n",name,value);
- }
- void student:: menu()
- {
- char *p;
- char s[LEN];
- int k;
- print_menu_student();
- while(fgets(s,LEN,stdin))
- {
- k=strtol(s,&p,10);
- if(p==s) continue;
- switch(k)
- {
- case -1: return ;
- case 1: { print(stdout,0);break;}
- default: { printf("Error number\n");}
- }
- print_menu_student();
- }
- return;
- }
- void print_menu_student()
- {
- printf("В классе STUDENT доступны следующие функции:\n");
- printf("-1-выйти\n");
- printf("1-печать\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement