: .TI-155
Cornescu R.
: Balan M.
2016
:
;
;
, ;
.
:
,
. , ,
; ,
,
, .
,
, ,
.
,
,
.
-
,
, .
,
,
,
,
,
.
:
) () - ,
, , , .
, , .
new. . main-,
.
b) () - ,
short . : ,
, / ,
, . ,
main, .
:
:
#include <stdlib.h>
#include <iostream>
#include <string.h>
#include <conio.h>
using namespace std;
struct Book
{
char *name;
char *author;
char *publication;
int pages;
int year;
void init(char *,char *, char *, int, int, int);
void setName(char *);
void setAuthor(char *);
void setPublication(char *);
void setPages(int);
void setYear(int);
void clear();
void print();
};
int compare(Book *,Book *);
void Book:: init(char *nam, char *aut, char *pub, int p, int y,int n)
{
if (n&&name)
delete[] name;
name = new char[strlen(nam) +1];
strcpy(name, nam);
if (n&&author)
delete[] author;
author = new char[strlen(aut) +1];
strcpy(author, aut);
if (n&&publication)
delete[] publication;
publication = new char[strlen(pub) +1];
strcpy(publication, pub);
pages = p;
year = y;
}
}
void Book:: setPages(int p)
{
pages = p;
}
void Book:: setYear(int y)
{
year = y;
}
void Book:: clear()
{
if (name)
delete[] name;
if (author)
delete[] author;
if (publication)
delete[] publication;
}
int main()
{
system("CLS");
int k;
Book *books;
char name[100];
char author[100];
char publications[100];
int pages;
int year;
int n1;
while(1)
{
cout<<" :\n";
cout<<"1 - :\n";
cout<<"2 - \n";
cout<<"3 - \n";
cout<<"4 - \n";
cout<<"5 - \n";
cout<<"6 - \n";
cout<<"7 - \n";
cin>>k;
switch(k)
{
case 1 :
{
int n;
cout<<" :\n";
cin>>n;
n1 = n;
books = new Book[n];
for(int i=0; i < n; i++)
{
cout<<" :\n";
cin>>name;
cout<<" :\n";
cin>>author;
cout<<" :\n";
cin>>publications;
cout<<" :\n";
cin>>pages;
cout<<" :\n";
cin>>year;
books[i].init(name, author, publications, pages, year, 0);
}
}continue;
case 2 :
{
for(int i=0; i<n1; i++)
{
cout<<i+1<<"- :"<<"\n\n";
books[i].print();
}
}
continue;
case 3 :
{
int t;
cout<<" :\n";
cout<<"1 - :\n";
cout<<"2 - \n";
cin>>t;
switch(t)
{
case 1 :
{
char nam[100];
cout<<" :\n";
cin>>nam;
for(int i=0;i < n1; i++)
{
if(strcmp(books[i].name,nam)==0)
{
cout<<i+1<<"- :"<<"\n\n";
books[i].print();
}
}
}
continue;
case 2 :
{
char aut[100];
cout<<" :\n";
cin>>aut;
for(int i=0;i < n1; i++)
if(strcmp(books[i].author,aut)==0)
{
cout<<i+1<<"- :"<<"\n\n";
books[i].print();
}
}
continue;
default:
cerr << " " << endl;
exit(EXIT_FAILURE);
}
continue;
case 4 :
{
int i,k,now;
cout<<" 1 - \n";
cin>>i;
cout<<" 2 - \n";
cin>>k;
now = compare(&books[i+1],&books[k+1]);
if (now == -1)
cout<<" \n";
else if(now == 0)
cout<<" ,
\n";
else if(now == 1)
cout<<" \n";
}
continue;
case 5 :
{
int opt, n;
cout<<" :\n";
cin>>n;
cout<<" :\n";
cout<<"1- :\n";
cout<<"2- :\n";
cout<<"3- :\n";
cout<<"4- :\n";
cout<<"5- :\n";
cin>>opt;
switch(opt)
{
case 1 :
{
cout<<" :\n";
cin>>name;
books[n-1].setName(name);
}
continue;
case 2 :
{
cout<<" :\n";
cin>>author;
books[n-1].setAuthor(author);
}
continue;
case 3 :
{
cout<<" :\n";
cin>>publications;
books[n-1].setPublication(publications);
}
continue;
case 4 :
{
cout<<" :\n";
cin>>pages;
books[n-1].setPages(pages);
}
continue;
case 5 :
{
cout<<" :\n";
cin>>year;
books[n-1].setYear(year);
}
continue;
default:
cerr << " " << endl;
exit(EXIT_FAILURE);
}
}
continue;
case 6 :
{
for(int i=0; i<n1; i++)
books[i].clear();
delete[] books;
cout<<" .\n";
}
continue;
case 7 :
{
cout << " ..." << endl;
exit(EXIT_SUCCESS);
}
continue;
default:
cerr << " " << endl;
exit(EXIT_FAILURE);
}
}
return 0;
}
}
:
#include <iostream>
#include <conio.h>
#include <math.h>
using namespace std;
struct Vector{
short *x;
int n; //-
};
int main(){
Vector *tab;
int N,num;
short val;
//
for (int i=0; i<N; i++){
cout << "v" << (i+1) << ": ";
for (int j=0; j<getN(&tab[i]); j++)
cout << getX(&tab[i],j) << " ";
cout << endl;
}
//
for (int i=0; i<N; i++)
cout << "\n " << (i+1) << " =" << SumPar(&tab[i]);
//
cout << "\n ?" << endl;
int v1,v2;
double n1,n2;
cin >> v1 >> v2;
if (v1<=0||v1>N||v2<=0||v2>N)
cout << "\n. \n";
else {
n1=Norma(&tab[v1-1]);
n2=Norma(&tab[v2-1]);
if (n1>n2) {
cout << "v" << v1 << " > v" << v2 << endl;
cout << n1 << " > " << n2 << endl;
}
else if (n1==n2){
cout << "v" << v1 << " = v" << v2 << endl;
cout << n1 << " = " << n2 << endl;
}
else if{
cout << "v" << v1 << " < v" << v2 << endl;
cout << n1 << " < " << n2 << endl;
}
}
//
for (int i=0; i<N; i++)
deleteVector(&tab[i]);
getch();
return 0;
}
:
. .
,
.