![]() Заглавная страница Избранные статьи Случайная статья Познавательные статьи Новые добавления Обратная связь FAQ Написать работу КАТЕГОРИИ: ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ТОП 10 на сайте Приготовление дезинфицирующих растворов различной концентрацииТехника нижней прямой подачи мяча. Франко-прусская война (причины и последствия) Организация работы процедурного кабинета Смысловое и механическое запоминание, их место и роль в усвоении знаний Коммуникативные барьеры и пути их преодоления Обработка изделий медицинского назначения многократного применения Образцы текста публицистического стиля Четыре типа изменения баланса Задачи с ответами для Всероссийской олимпиады по праву ![]() Мы поможем в написании ваших работ! ЗНАЕТЕ ЛИ ВЫ?
Влияние общества на человека
Приготовление дезинфицирующих растворов различной концентрации Практические работы по географии для 6 класса Организация работы процедурного кабинета Изменения в неживой природе осенью Уборка процедурного кабинета Сольфеджио. Все правила по сольфеджио Балочные системы. Определение реакций опор и моментов защемления |
Заголовочный файл MyConvert.hСодержание книги Поиск на нашем сайте
#pragma once using namespace System; using namespace System::Windows::Forms; class MyConvert { public:
static int copyto(char** ss,char buf[]); static int copyto(int* i,char buf[]); static int copyto(double* d,char buf[]); static int copyto(char* buf,String* S,int count=-1); static int copyto(char** str,String* S); static int copyto(TextBox* m[],String* s[],int count,int first_s=0,int first_m=0); MyConvert(void); public: ~MyConvert(void); }; 2. Файл реализации MyConvert.cpp #include "StdAfx.h" #include "MyConvert.h" #include "validator.h" int MyConvert::copyto(char** s,char buf[]) { delete [](*s); *s=new char[strlen(buf)+1]; strcpy(*s,buf); return 1;}
int MyConvert::copyto(int* i,char buf[]) {if(IsInt(buf)) *i=atoi(buf); else return 0; return 1;} int MyConvert::copyto(double* i,char buf[]) {return 1;}
#using <mscorlib.dll> #include <windows.h>
int MyConvert::copyto(char* buf,System::String* S,int count) {int i, state; for(i=0;i<S->Length && i<count;i++){ wchar_t t=S->Chars[i]; state=WideCharToMultiByte(CP_ACP, 0, &t, 1, &buf[i], 1, NULL, NULL); } buf[i]='\0'; return state;}
int MyConvert::copyto(char** str,System::String* S) { delete [](*str); *str=new char [S->Length+1]; return MyConvert::copyto(*str,S); } int MyConvert::copyto(TextBox* m[],String* s[],int count,int first_s,int first_m) { if(s==0)return 0; while(count-->0) m[first_m++]->Text=s[first_s++]; return 1; }
MyConvert::MyConvert(void) { }
MyConvert::~MyConvert(void) {} 3. Заголовочный файл "exeptions.h" #pragma once void ExeptionLetters(char* str); void ExeptionInt(char* str); void ExeptionFloat(char* str); void ExeptionRange(double d,double min,double max); void ExeptionFopen(char* str); void ExeptionFound(); void ExeptionEmpty(); void ExeptionInvalidValue(char* str); Файл реализации exeptions.cpp void ExeptionLetters(char* str) {String* s=new String(str); s=String::Concat(S"\nString\t",s,S"\t must include inglish letters\n"); MessageBox::Show(s,S"ExeptionInt ");}
void ExeptionInt(char* str) {String* s=new String(str); s=String::Concat(S"\nString\t",s,S"\t must include letters of digits\n"); MessageBox::Show(s,S"ExeptionInt ");}
void ExeptionFloat(char* str){}
void ExeptionRange(double d,double min,double max) {String* s1=d.ToString(); String* s2=min.ToString(); String* s3=max.ToString(); s1=String::Concat(S"\n Value\t",s1,S"\t must be latter then ",s2,S"and must be greater then",s3); MessageBox::Show(s1,S"ExeptionRange");} void ExeptionFopen(char* str) {String* s=new String(str); s=String::Concat(S"\nFile\t",s,S"\t open error\n"); MessageBox::Show(s,S"ExeptionFopen");} void ExeptionInvalidValue(char* str) {String* s=new String(str); s=String::Concat(S"\nValue\t",s,S"\t Invalid \n"); MessageBox::Show(s,S"Invalid Value");} void ExeptionFound() {MessageBox::Show("Просмотр закончен. Искомый элемент не найден" ,"Поиск");} void ExeptionEmpty() {MessageBox::Show("Поля ввода не должны быть пустыми" ,"Input");} 5. Заголовочный файл "validator.h" #pragma once #include "exeptions.h" int IsLetters(char* s); int IsInt(char* s); int IsFloat(char* s); int InRange(double d,double min,double max); Файл реализации validator.cpp #include "stdafx.h" #include "validator.h" int IsLetters(char* s)
{if(s==0)return 0; for(;*s!='\0' && toupper(*s)>='A' && toupper(*s)<='Z';s++) ; if (*s!='\0') {ExeptionLetters(s); return 0;} return 1;}
int IsInt(char* s) {if(s==0)return 0; for(;*s!='\0' && *s>='0' && *s<='9';s++) ; if (*s!='\0') {ExeptionInt(s); return 0;} return 1;}
int IsFloat(char* s){if(s==0)return 0; return 1;}
int InRange(double d,double min,double max) {if(d<min|| d>max) {ExeptionRange(d,min,max); return 0;} return 1;} Заголовочный файл io.h #pragma once typedef FILE* File; int eof(File fp); int eof(); void clear(File fp); void clear(); int input(File fp,char* s); int input(File fp,char* s,int lim); int input(File fp,char** s); int input(File fp,int* i); int input(File fp,double* i); int input(char* s); int input(char** s); int input(int* i); int input(double* d);
int output(char* s); int output(File fp,char* s);
using namespace System; using namespace System::Windows::Forms; int input(TextBox * t,char* s,int count); int input(TextBox * t,char** s); int input(TextBox * t,int *i); Файл реализации io.cpp #include "stdafx.h" #include "io.h" #include "MyConvert.h" #define MAX 256 char buf[MAX]; using namespace std; int eof(FILE* fp){return feof(fp);} int eof(){return feof(stdin); } void clear(FILE* fp){rewind(fp);} void clear(){rewind(stdin); }
int input(File fp,char* s) {int state=fscanf(fp,"%s",s); return state && state!=EOF; } int input(FILE* fp,char** s) { return input(fp,buf) && MyConvert::copyto(s,buf); }
int output(FILE* fp,char* s) {return fprintf(fp,"%s\n",s);}
int input(FILE* fp,int* i) {return input(fp,buf) && MyConvert::copyto(i,buf);}
int input(FILE* fp,double* i) {return 1;}
int input(char* s) {return input(stdin,s);} int input(char** s) {return input(stdin,s);} int input(int* i) {return input(stdin,i);} int input(double* d){return input(stdin,d);} int output(char* s) {return output(stdout,s);}
int input(FILE* fp,char* s,int lim) { int c; while((c=getc(fp))!=EOF && isspace(c)) ; if(c==EOF) return 0; *s++=c;--lim; while(--lim>0 && (c=getc(fp))!=EOF &&!isspace(c)) *s++=c; *s='\0'; return (c== EOF||lim==0)? 0:1; } using namespace System; using namespace System::Windows::Forms;
int input(TextBox * t,char* s,int count) {return MyConvert::copyto(s,t->Text,count); } int input(TextBox * t,char** s) { return input(t,buf,MAX) && MyConvert::copyto(s,buf); }
int input(TextBox * t,int *i) {return input(t,buf,MAX) && MyConvert::copyto(i,buf);} Заголовочный файл MyDate.h # pragma once #include "io.h" class MyDate { int day,month,year; static int daytab[2][13]; static char* MonthName[13]; static char* DayNames[8]; public: MyDate(void); int get_day(){return day;} int get_month(){return month;} int get_year(){return year;} int get_day()const {return day;} int get_month()const {return month;} int get_year()const {return year;} public: ~MyDate(void); MyDate(int d,int m,int y); MyDate (char* s); MyDate (const MyDate&); void assign (const MyDate& t); void dispose (); MyDate* copy(); int validate(); static int vis(int y) { return ((!(y%4))&&(y%100)||(!(y%400))); } char* ToPchar(); String* ToString();
int equal(const MyDate& t); int cmp(const MyDate& t);
int input(File fp); int input(); int output(File f); int output(); int input(TextBox * t1, TextBox * t2, TextBox * t3);
};
Файл MyDate.h #include "StdAfx.h" #include "MyDate.h"
#include "exeptions.h" int MyDate::daytab[2][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}}; char* MyDate::MonthName[13]={"Wrong month","January","February","March","April","May","June","July","August","September","October","November","December"}; char* MyDate::DayNames[8]={"Wrong day","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}; MyDate::MyDate(void) {day=month=year=0; }
MyDate::~MyDate(void) { } MyDate::MyDate(int d,int m,int y) { day=d; month=m; year=y; if(!validate()) ExeptionInvalidValue("MyDate");
} int MyDate::validate() { return (year>0&&month>0&&month<=12&&day>0&&day<=daytab[vis(year)][month]); } MyDate::MyDate (char* s){} MyDate::MyDate (const MyDate& d) {day=d.day; month=d.month; year=d.year;} void MyDate::assign (const MyDate& d) {day=d.day; month=d.month; year=d.year;} void MyDate::dispose (){} MyDate* MyDate::copy() {return new MyDate();} char* MyDate::ToPchar() {char s[256],buf[256],*s1; s[0]='\0'; itoa(day,buf,10); strcat(s,buf); strcat(s,"."); itoa(month,buf,10); strcat(s,buf); strcat(s,"."); itoa(year,buf,10); strcat(s,buf); s1=new char[strlen(s)+1]; strcpy(s1,s); return s1;} String* MyDate::ToString() {return new String(ToPchar());}
int MyDate::equal(const MyDate& d) {return day==d.day && month==d.month && year==d.year;}
int MyDate::cmp(const MyDate& d) {if(year!=d.year)return year-d.year; else if(month!=d.month)return month-d.month; else return day-d.day; }
int MyDate::input(File fp) {int state=1; state&=::input(fp,&day); if(eof(fp)) return 0; state&=::input(fp,&month); if(eof(fp)) return 0; state&=::input(fp,&year); if(eof(fp)) return 0; return state;} int MyDate::input() {int state=1; ::output("day"); state&=::input(&day); if(eof()) return 0; ::output("month"); state&=::input(&month); if(eof()) return 0; ::output("year"); state&=::input(&year); if(eof()) return 0; return state;} int MyDate::output(File f) {return fprintf(f,"%d\t%d\t%d\n", day,month,year); } int MyDate::output() {return output(stdin);} int MyDate::input(TextBox * t1, TextBox * t2, TextBox * t3) {int state=1; state&=::input(t1,&day); state&=::input(t2,&month); state&=::input(t3,&year); return state;}
|
||||||
Последнее изменение этой страницы: 2016-07-11; просмотров: 263; Нарушение авторского права страницы; Мы поможем в написании вашей работы! infopedia.su Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав. Обратная связь - 18.117.112.183 (0.007 с.) |