0% found this document useful (0 votes)
35 views

Referat: Fisiere, Baze de Date"

The document is a lab report in Romanian for a university course on data structures and algorithms. It details creating a database to store information on medications, including name, type, and price. The program code allows the user to create, add to, display, and write the medication data to a file.

Uploaded by

NIK manik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Referat: Fisiere, Baze de Date"

The document is a lab report in Romanian for a university course on data structures and algorithms. It details creating a database to store information on medications, including name, type, and price. The program code allows the user to create, add to, display, and write the medication data to a file.

Uploaded by

NIK manik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

MINISTERUL EDUCAŢIEI, CULTURII ȘI CERCETĂRII AL REPUBLICII MOLDOVA

UNIVERSITATEA TEHNICĂ A MOLDOVEI


Facultatea Calculatoare, Informatică şi Microelectronică
Departamentul Microelectronică și Nanotehnologii

REFERAT
la lucrarea de laborator nr.5
Tema: „Fisiere,Baze de date”
Disciplina: „Structuri de date si algoritmi”

A elaborat
A verificat conf. univ., dr. Stadler Lucia

Chișinău 2019
Sarcini:
Sa se elaboreze o baza de date in care sa contina
tema:Medicamente.

Program:
#include <stdio.h>
#include <conio.h>
#include <string.h>

int nr_ut = 0;
FILE* file;
char nume_fisier[15];
int j,i;
int f;
typedef struct Medicamente{
char denumire[11];
char tip[11];
int pret;
} Medicamente;

Medicamente lista[10];

void creare(){
int x;
printf("Cati utilizatori doriti sa introduceti?(max
10)\n");
fflush(stdin);
fscanf(stdin, "%d", &x);
nr_ut = x;
for(j = 0; j < x; j++)
{
fflush(stdin);
printf("Intoduceti Denumire: ");
scanf("%10s", lista[j].denumire);
fflush(stdin);
printf("Intoduceti tip: ");
scanf("%10s", lista[j].tip);
fflush(stdin);
printf("Introduceti pret: ");
scanf("%d", &lista[j].pret);
fflush(stdin);
}
}

void afisare(void)
{
for(i = 0; i < nr_ut; i++)
{
printf("| %s | ", lista[i].denumire);
printf("%s |", lista[i].tip);
printf(" %d | ", lista[i].pret);
printf("\n");
}
}

void scrie_in_fisier(FILE* fisier)


{
for(int k = 0; k < nr_ut; k++)
{
fprintf(fisier, "%s ", lista[k].denumire);
fprintf(fisier, "%s ", lista[k].tip);
fprintf(fisier, "%d ", lista[k].pret);
fputc('\n', fisier);
}
}
void adaugare(void)
{
fflush(stdin);
char str[25];
printf("Introduceti noua denumire: ");
scanf("%s", str);
strcpy(lista[nr_ut].denumire, str);
printf("Introduceti tip: ");
scanf("%s", str);
strcpy(lista[nr_ut].tip, str);
printf("Introduceti pret: ");
fflush(stdin);
scanf("%d", &lista[nr_ut].pret);
fflush(stdin);
nr_ut++;
}

int meniu(){

printf("Alegeti o optiune: \n");


printf("\t1.Creare.\n");
printf("\t2.Adaugare.\n");
printf("\t3.Afisare.\n");
printf("\t4.Scrie in fisier.\n");
printf("\t5.Iesire.\n");

int main()
{
int optiune = 0;
printf("Introduceti numele fisierului: ");
fscanf(stdin, "%14s", nume_fisier);
file = fopen(nume_fisier, "w+");
while(optiune != 5)
{
meniu();
scanf("%d", &optiune);
switch(optiune){
case 1: creare();break;
case 2: adaugare();break;
case 3: afisare();break;
case 4: scrie_in_fisier(file);break;
default: printf("Aceasta optiune nu exista!\n");
break;

}
}
fclose(file);
printf("Sfarsit!");
}
Rezultatul:

You might also like