Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Studente : Scia Massimiliano
- Classe : 3IC
- Data : 19/03/2012 16:19
- Nome del file : ordinamento libri
- */
- #include <iostream>
- #include <cmath>
- #include <ctime>
- #include <cstdlib>
- #include <cctype>
- #include <windows.h>
- #include <fstream>
- #include <time.h>
- #include <string>
- #include <stdio.h>
- #define N 100
- using namespace std;
- /*void struct_swap(book *a, book *b){
- book temp;
- temp.price=a->price;
- a->price=b->price;
- b->price=temp.price;
- }//struct_swap*/
- struct book{
- float price;
- string title;
- string author;
- };//book
- void bg_col(){
- system("color 70");
- }
- void end(void){
- fflush(stdin);
- cout<<"\n\nPremere Invio per continuare.";
- getchar();
- }//end
- int dim(){
- int n;
- cout<<"\nQuanti libri vuoi inserire? ";
- cin>>n;
- return n;
- }//dim
- book books_info(){
- book b;
- fflush(stdin);
- cout<<"\nAutore/i: ";
- getline(cin,b.author);
- fflush(stdin);
- cout<<"\nTitolo: ";
- getline(cin,b.title);
- fflush(stdin);
- cout<<"\nPrezzo: ";
- cin>>b.price;
- fflush(stdin);
- return b;
- }//books_info
- void books(book b[], int n){
- cout<<"\n\n";
- for(int i=0;i<n;i++){
- cout<<"\n\t\tLibro "<<i+1<<" :\n";
- b[i]=books_info();
- }//for
- }//books
- void sort_by_price(book b[], int n){
- for(int i=0;i<n;i++)
- for(int j=i+1;j<n;j++)
- if(b[i].price>b[j].price)
- swap(b[i],b[j]);
- }//sort_by_price
- void sort_by_title(book b[], int n){
- for(int i=0;i<n;i++)
- for(int j=i+1;j<n;j++)
- if(b[i].title.compare(b[j].title)>0)
- swap(b[i],b[j]);
- }//sort_by_title
- void sort_by_author(book b[], int n){
- for(int i=0;i<n;i++)
- for(int j=i+1;j<n;j++)
- if(b[i].author.compare(b[j].author)>0)
- swap(b[i],b[j]);
- }//sort_by_author
- void visualize(book b[] , int n){
- cout<<"\n\nLe informazioni riguardanti i libri sono:\n";
- for(int i=0;i<n;i++){
- cout<<"\n\nAutore/i: "<<b[i].author;
- cout<<"\n\nTitolo: "<<b[i].title;
- cout<<"\n\nPrezzo: "<<b[i].price;
- }//for
- }//visualize
- void visualize_p(book b[] , int n){
- cout<<"\n\nOrdinamento per prezzo:\n";
- for(int i=0;i<n;i++){
- cout<<"\n\nAutore/i: "<<b[i].author;
- cout<<"\n\nTitolo: "<<b[i].title;
- cout<<"\n\nPrezzo: "<<b[i].price;
- }//for
- }//visualize
- void visualize_t(book b[] , int n){
- cout<<"\n\nOrdinamento per titolo:\n";
- for(int i=0;i<n;i++){
- cout<<"\n\nAutore/i: "<<b[i].author;
- cout<<"\n\nTitolo: "<<b[i].title;
- cout<<"\n\nPrezzo: "<<b[i].price;
- }//for
- }//visualize
- void visualize_a(book b[] , int n){
- cout<<"\n\nOrdinamento per autore:\n";
- for(int i=0;i<n;i++){
- cout<<"\n\nAutore/i: "<<b[i].author;
- cout<<"\n\nTitolo: "<<b[i].title;
- cout<<"\n\nPrezzo: "<<b[i].price;
- }//for
- }//visualize
- int main(){
- book biblioteca[N];
- bg_col();
- int n=dim();
- books(biblioteca,n);
- visualize(biblioteca,n);
- sort_by_price(biblioteca,n);
- visualize_p(biblioteca,n);
- sort_by_title(biblioteca,n);
- visualize_t(biblioteca,n);
- sort_by_author(biblioteca,n);
- visualize_a(biblioteca,n);
- end();
- return 0;
- }//main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement