Computer Sciences 19/09/2011 TURN A Exam A. Theory

Documenti analoghi
Informatica 19/09/2011 TURNO A Compito A. Teoria

Informatica 19/09/2011 TURNO B Compito A. Teoria. Risultato: A ca2 : B ca2: overflow:

Informatica 19/09/2011 TURNO C Compito A. Teoria. Risultato: n1 ca2 : n2 ca2: overflow:

Informatica 27/06/2012 durata complessiva: 2h

Informatica I Facoltà di Ingegneria Prova scritta del 20/01/2014 TURNO B

Informatica I Facoltà di Ingegneria Prova scritta del 20/01/2014 TURNO A

Corso di Informatica A.A

Linguaggio C: sintassi. Operatore. Precedenza degli operatori. Costrutti decisionali. logici. relazionali. matematici. switch + - * / % < > <= >= ==!

GESTIONE DEI FILE IN C. Docente: Giorgio Giacinto AA 2008/2009

Gestione dei file. Stefano Ferrari. Università degli Studi di Milano Programmazione. anno accademico

Le stringhe. Le stringhe sono sequenze di caratteri,

Le stringhe. Le stringhe sono sequenze di caratteri,

Funzioni di libreria. KP pp , , , 589, DD pp , , ,

Stringhe in C. Emilio Di Giacomo

Librerie C. Corso di Linguaggi e Traduttori 1 AA Corso di Linguaggi e Traduttori 1 AA stdio.h

Funzioni matematiche (1) KP p. 112,573. Corso di Fondamenti di Programmazione canale E-O. Funzioni matematiche (2) Funzioni matematiche (3)

Laboratorio di Algoritmi e Strutture Dati

Librerie C. Corso di Linguaggi e Traduttori 1 AA

Stringhe. Prof. Lorenzo Porcelli

Laboratorio di Algoritmi

Caratteri e stringhe

Settimana n.8. Contenuti. Obiettivi Caratteri Vettori di caratteri Stringhe

Linguaggio C: Stringhe Valeria Cardellini

L accesso ai dispositivi esterni (tastiera, monitor, file,...) viene gestito mediante canali di comunicazione.

Dispensa 13 CORSO DI PROGRAMMAZIONE A.A CORSO DI LAUREA IN INGEGNERIA E SCIENZE INFORMATICHE CESENA. Laboratorio

Lezione 7: Funzioni e gestione dei File

Caratteri e stringhe

Settimana n.12. Obiettivi File!di!testo. Contenuti Concetto!di!file!e!funzioni! fopen/fclose Funzioni!fgets+sscanf Approfondimenti!su!printf! e!

I file possono essere manipolati (aperti, letti, scritti ) all interno di programmi C. dischi nastri cd

Le strutture. Una struttura C è una collezione di variabili di uno o più tipi, raggruppate sotto un nome comune.

Codifica dei Tipi di Dati in Linguaggio C

LEZIONE 1 LE BASI DEL LINGUAGGIO C

Streams e disk files

Una stringa di caratteri in C è un array di caratteri terminato dal carattere '\0' a p e \0

Linguaggio C e sistema operativo

Operatori sui bit. op1=60; op2=240; ; op3 = op1 op2; op3 assume valore 252

Le strutture. Una struttura C è una collezione di variabili di uno o più tipi, raggruppate sotto un nome comune.

LA CODIFICA LORENZO BRACCIALE

Laboratorio di Programmazione

Il linguaggio C. Breve panoramica su stdio.h

Corso di Fondamenti di Informatica Ingegneria delle Comunicazioni BCOR Ingegneria Elettronica BELR Introduzione al C Unità 9 File

Matrici, stringhe e I/O da file

Sulla libreria standard, III. Manipolare file con stdio.h

I/O da file. Matrici. Stringhe. Memory leakage. Matrici, stringhe e I/O da file

Scrittura formattata - printf

Input/Output. Lettura e scrittura Caratteri e Stringhe: Terminale e file. Input/output. caratteri stringhe formattato ascii binari

Lezione integrativa: Dal C++ al C

Introduzione al C. Unità 8 Stringhe

Operazioni su file di caratteri

Introduzione al C. Unità 8 Stringhe. S. Salza, C. Ciccotelli, D. Bloisi, S. Peluso, A. Pennisi

Sommario FONDAMENTI DI INFORMATICA 1. Il tipo FILE. Passaggio da standard I/O. LINGUAGGIO C Gestione dei file

STRINGHE: ARRAY DI CARATTERI! a p e \0

Le librerie standard. ! La libreria standard del C è in realtà un insieme di librerie

I file Laboratorio di Linguaggi di Programmazione a.a. 2001/2002

Laboratorio di Informatica

string.h strcpy strc strcat strcmp strcmp strchr strstr strstr i t r ; s r \0 int strlen(char* str) char pippo[]={ p, i, p, p, o, \0 \ };

LIBRERIE STANDARD in C. LIBRERIE STANDARD in C

Librerie Stringhe. Librerie e stringhe. Lezione 9. Laboratorio di Programmazione I. Corso di Laurea in Informatica A.A. 2015/2016

Linguaggio C La libreria standard

I/O in linguaggio C. I/O di caratteri e stringhe

Linguaggio C La libreria standard

Sistemi Operativi (M. Cesati)

Sistemi Operativi (M. Cesati)

char* titolo= Libreria sulle stringhe Esempi: (strcpy) (strstr)... Laboratorio di Informatica L-A 1

FONDAMENTI DI INFORMATICA. Prof. PIER LUCA MONTESSORO Ing. DAVIDE PIERATTONI. Facoltà di Ingegneria Università degli Studi di Udine

Input / Output. Come già detto, input e output sono realizzati in C da funzioni di stdio.h all'interno della libreria standard

Le stringhe. Le stringhe sono sequenze di caratteri,

Introduzione al C. Unità 8 Stringhe. D. Bloisi, S. Peluso, A. Pennisi, S. Salza

Scope (visibilità) Scope di un identificatore

file fisico file logico

Introduzione al C. Stream e disk file

Operazioni sulle stringhe Corso di Fondamenti di Informatica Ingegneria delle Comunicazioni BCOR Ingegneria Elettronica BELR

s r t i r n i g n. g h s r t c r p c y s r t c r a c t s r t c r m c p s r t c r h c r s r t s r t s r

Espressioni ed operatori

Dati due punti sul piano calcolare la loro distanza

FILE: tipo operazione Istruì. prototipo esempi lettura di un carattere fgetc Int fgetc(file *flusso) Vedi sotto

Input / Output. Come già detto, input e output sono realizzati in C da funzioni di stdio.h all'interno della libreria standard

Il linguaggio C. Puntatori e dintorni

DOTT. ING. LEONARDO RIGUTINI DIPARTIMENTO INGEGNERIA DELL INFORMAZIONE UNIVERSITÀ DI SIENA VIA ROMA SIENA UFF

Introduzione al linguaggio C

char* titolo= { l, e,, s, t, r, i, n, g, h, e, \0 };

programmazione distribuita Introduzione Introduzione alla programmazione distribuita

Scope (visibilità) Scope di un identificatore

Laboratorio di Sistemi Operativi Marzo-Giugno 2008 Matricole congrue 0 mod 3

Introduzione al linguaggio C Primi programmi

Laboratorio di Sistemi Operativi primavera 2009

Input/output console file caratteri stringhe formattato ascii binari

INFORMATICA A. Titolo presentazione sottotitolo. Laboratorio n 5 Dott. Michele Zanella Ing. Gian Enrico Conti

Introduzione al C. Unità 9 File. D. Bloisi, S. Peluso, A. Pennisi, S. Salza

Sommario ELEMENTI DI INFORMATICA. Passaggio da standard I/O. LINGUAGGIO C Gestione dei file

Gestione dinamica della memoria Stringhe File

Struttura dati FILE. Motivazioni: memorie a confronto

Un esempio per cominciare. Inizio e fine di un programma. La somma di 3 numeri PASCAL ANSI C. Regole sintattiche

Transcript:

Name and Surname Matricola Course Poli@Home 1(AAAA-BARB) 2(BARC-BOT) 3(BOU-CASA) 4(CASB-CHZ) 5(CIA-COND) 6(CONE-DELR) 7(DELS-FEQ) 8(FER-GEQ) 9(GER-JOZ) 10(JPA-MALI) 11(MALJ-MOD) 12(MOE-PAK) 13(PAL-PORS) 14(PORT-ROQ) 15(ROR- SIGN) 16(SIGO-TRIO) 17(TRIP-ZZZ) 18(Automotive) Solo Prog English Theory Question 1 Result Given the integer numbers n1=-7171 e n2=-abcd, expressed in base 16, represent them in 2 s complement on 16 bits, then calculate the sum S (operand in 2 s complement) and discuss the potential presence of overflow. Question 2 If you want to store on a pen drive A text of 3000 characters, on 50 lines, written in ASCII An audio file without compression, with a duration of 5 seconds and sampled at 30 Hz (30 samples per second), where each sample occupies 6 bytes Calculate the total amount of bytes that are necessary, justifying the result. Question 3 Explain the meaning of logic gate and make at least two examples.

Programming The file map.txt contains a map of size N x N. The map represents the altitude in meters of a region. Possible values are in the range from 0 to 3000. N is a constant known a priori and defined by means of a define directive. Each line of the file describes a row of the map, and contains N integers separated by a space: <h 1,1 > <h 1,2 > <h 1,3 > <h 1,N > <h 2,1 > <h 2,2 > <h 2,3 > <h 2,N > <h N,1 > <h N,2 > <h N,3 > <h N,N > Write a C program to analyze portions of the map. The program should receive 4 integers as arguments from the command line, representing the extremes of a rectangle (region of interest) within the map: <x1> <y1> <x2> <y2> where (<x1>, <y1>) are the coordinates of the upper left corner of the rectangle, while (<x2>, <y2>) are the coordinates of the lower right corner. The box (0, 0) is at the upper left corner of the map, therefore x1 x2 and y1 y2. The program should provide the following information as output: Maximum altitude within the region of interest Minimum altitude (> 0) within the region of interest Percentage of sea within the region of interest (altitude == 0) Percentage of plain areas within the region of interest (0 < altitude < 200) Percentage of hills within the region of interest (200 <= altitude <= 600) Percentage of mountains within the region of interest (altitude > 600) All the percentages have to be represented with exactly 2 decimal digits. In case of error in the format of the file (integers not in the range from 0 to 3000, or insufficient number of data in the file) the program should print the message File format error and terminate the execution. For example, if N is equal to 4 and the file contains the following data: 210 630 22 102 240 500 35 923 0 611 152 883 14 57 64 613 If the program is executed with arguments 0 0 1 2 the output should be: Maximum altitude: 630 Minimum altitude: 210 Sea: 16.67% Plain: 0.00% Hills: 50.00% Mountains: 33.33%

#include <stdio.h> FILE *fopen(char *filename, char * mode) Apertura di un file (mode: r lettura w scrittura a append) FILE *freopen(char *filename, char * mode, FILE *file_pointer) - Riassegna un file puntatore ad un file diverso. int fclose(file *file_pointer) - Chiude un file int feof(file *file_pointer) - Controlla se e' stato incontrato un end-of-file in un file. int fflush(file *file_pointer) - Svuota il buffer di un file. int getchar(void) - Legge un carattere da "stdin" (tastiera) int fgetc(file *file_pointer) - Prende un carattere da un file char *gets(char *buffer) - Legge una riga da "stdin" (tastiera) char *fgets(char *string, int maxchar, FILE *file_pointer) - Legge una riga da un file. int printf(char *format _string, ) - Scrive output formattato su "stdout" (schermo) int fprintf(file *file_pointer, char *format_string, ) - Scrive output formattato in un file. int sprintf(char *string, char *format_string, ) - Scrive output formattato su una stringa int fputc(int c, FILE *file_pointer) - Scrive un carattere in un file int putchar(int c) - Scrive un carattere su "stdout" (schermo) int puts(char *string) - Scrive una stringa su "stdout" (schermo) int fputs(char *string, FILE *file_pointer) - Scrive una stringa in un file. int scanf(char *format_string, args) - Legge input formattato da "stdin" (tastiera) int fscanf(file *file_pointer, char *format string, args) - Legge input formattato da file int sscanf(char *buffer, char *format_string, args) - Legge input formattato da una stringa EOF end of file (costante a valore negativo) NULL - puntatore nullo (valore 0) #include <stdlib.h> double atof(char *string) - Converte una stringa in un valore in floating point. int atoi(char *string) - Converte una stringa in un valore integer. int atol(char *string) - Converte una stringa in un valore long integer. void exit(int val) Termina il programma, restituendo il valore val. EXIT_FAILURE - costante per segnalare terminazione senza successo del programma con exit(); valore diverso da zero EXIT_SUCCESS - segnala terminazione con successo del programma con exit(); vale 0 #include <string.h> char *stpcpy (char *dest, char *src) - Copia una stringa in un'altra. Restituisce dest char *strncpy(char *s1, char *s2, size_t n) - Copia i primi "n" caratteri di s2 in s1. Restituisce s1 int strcmp(char *s1, char *s2) - Confronta s1 e s2 per determinare l'ordine alfabetico (<0, s1 prima di s2, 0 uguali, >0 s1 dopo s2) int strncmp(char *s1, char *s2, size_t n) - Confronta i primi "n" caratteri di due stringhe. char *strcpy(char *s1, char *s2) - Copia s2 in s1. Restituisce s1 int strlen(char *string) - Determina la lunghezza di una stringa. char *strcat(char *s1, char *s2, size_t n) - Aggiunge s2 a s1. Ritorna s1 char *strncat(char *s1, char *s2, size_t n) - Aggiunge "n" caratteri di s2 a s1. Ritorna s1 char *strchr(char *string, int c) - Cerca la prima occorrenza del carattere c in string; restituisce un puntatore alla prima occorrenza di c in s, NULL se non presente char *strrchr(char *string, int c) - Cerca l'ultima occorrenza del carattere c in string char* strstr(char* s, char* t) - Restituisce un puntatore alla prima occorrenza di t all'interno di s. Restituisce NULL se t non è presente in s. char* strtok(char* s, const char* t) - scompone s in token, i caratteri che delimitano i token sono contenuti in t. Restituisce il puntatore al token (NULL se non ne trova nessuno). Alla prima chiamata in s va inserita la stringa da scomporre e in t i caratteri che delimitano i vari token. Per operare sulla stessa stringa, alle successive chiamate al posto di s si deve passare NULL #include <ctype.h> int isalnum(int c) - Vero se c e' alfanumerico. int isalpha(int c) - Vero se c e' una lettera dell'alfabeto. int iscntrl(int c) - Vero se c e' un carattere di controllo. int isdigit(int c) - Vero se c e' un numero decimale. int islower(int c) - Vero se c e' una lettera minuscola. int isprint(int c) - Vero se c e' un carattere stampabile. int ispunct (int c) - Vero se c e' un carattere di punteggiatura. int isspace(int c) - Vero se c e' un carattere spazio. int isupper(int c) - Vero se c e' una lettera maiuscola. tolower(int c) - Converte c in minuscolo. int toupper(int c) - Converte c in maiuscolo. #include <math.h> int abs (int n) valore assoluto intero long labs(long n) valore assoluto long double fabs (double x ) valore assoluto di x double acos(double x) - arcocoseno double asin(double x) - arcoseno double atan(double x) - arcotangente double atan2(double y, double x) arcotangente di y/x. double ceil(double x) intero superiore a x double floor(double x) intero inferiore a x. double cos(double x) x in radianti double sin(double x) x in radianti double tan(double x) x in radianti double cosh(double x) coseno iperbolico double sinh(double x) seno iperbolico double tanh(double x) tangente iperbolica double exp(double x) - e x double log(double x) - log(x). double log10 (double x ) logaritmo base 10 double pow (double x, double y) - x y int rand (void) intero casuale tra 0 e RND_MAX. int random(int max_num) valore casuale tra 0 e max_num. void srand(unsigned seed) inizializza la sequenza di valori casuali double sqrt(double x) radice quadrata #include <limits.h> INT_MAX - Indica il più grande valore che è possibile rappresentare con un int. INT_MIN - Indica il più piccolo valore che è possibile rappresentare con un int. LONG_MAX - Indica il più grande valore che è possibile rappresentare con un long. LONG_MIN - Indica il più piccolo valore che è possibile rappresentare con un long. #include <float.h> FLT_MAX, DBL_MAX - Indica il più grande valore che è possibile rappresentare con un float (o double) FLT_MIN, DBL_MIN - Indica il più piccolo valore che è possibile rappresentare con un float (o double)

Informatica 19/09/2011 TURNO A