Sunteți pe pagina 1din 5

///Ex fisiere

#include <iostream>

#include <stdio.h>

using namespace std;

int A[1000];

int N;

int SUM (int *ptr,int n){ //nr de elemente ale tabloului

int suma=0;

for(int i=0; i<n; i++)

suma+=ptr[i];

return suma;

int main() {

FILE *fp;

fp=fopen("A.txt", "r");

if (fp==NULL) { cout<<"\n fisierul nu poate fi deschis "<<endl; exit(1);}

fscanf(fp,"%d",&N);

cout<<"Tabloul setat: "<<endl;

for(int i=0; i<N ; i++) {

fscanf(fp,"%d",&A[i]);

cout<<A[i]<<"\t";

cout<<endl<<endl<<"Tabloul prelucrat: "<<endl;

fclose(fp);

fp=fopen("BC.txt","w");
if( fp==NULL) { cout<<"\n fisierul nu exista "; exit(1);};

int B [20]={0}, C [20]={0}, par=0, impar=0;

for(int i=0; i<N; i++){

if (A[i]%2==0) {

B[par]=A[i];

par++;

else {

C[impar]=A[i]; impar++;}

cout<<SUM(B,par)<<"\t"<<SUM(C,impar) <<endl;

fprintf(fp,"%d %d \n", SUM(B,par), SUM(C,impar));

for(int i=0;i<par;i++){

cout<<B[i]<<"\t";

fprintf(fp,"%d ",B[i]);

cout<<endl;

fprintf(fp,"\n");

for(int i=0;i<impar;i++) {

cout<<C[i]<<"\t";

fprintf(fp,"%d ",C[i]);

fclose(fp);

}
//EEX 2

#include <iostream>

#include <string.h>

using namespace std;

struct elev {

char nume [15];

char prenume[15];

int clasa;

int n1, n2, n3,n4;

float nota_med;

int x;

};

void afis(elev el[7]){

for(int i=0; i<7;i++){

cout<<"Nume Prenume: "<<el[i].nume<<"\t"<<el[i].prenume<<endl;

cout<<"Clasa: "<<el[i].clasa<<endl;

cout<<"Notele: "<<el[i].n1<<"\t"<<el[i].n2<<"\t"<<el[i].n3<<"\t"<<el[i].n4<<endl;

el[i].nota_med=(el[i].n1+el[i].n2+el[i].n3+el[i].n4)/4.0;

cout<<"Nota medie: "<<el[i].nota_med<<endl;

int main() {

elev el[7];

FILE *fp;

fp=fopen("elev.txt","r");

if(fp==NULL) { cout<<"\n Fisierul nu poate fi gasit !!! "; exit(1);}


for(int i=0;i<7;i++){

fscanf(fp,"%s %s",&el[i].nume,&el[i].prenume);

fscanf(fp,"%d",&el[i].clasa);

fscanf(fp,"%d %d %d %d",&el[i].n1,&el[i].n2,&el[i].n3,&el[i].n4);

fclose(fp);

afis(el);

cout<<endl<<endl;

//Ordonarea dupa clasa in ordine crescatoare:

elev x;

for(int i=0;i<6;i++){

for(int j=i;j<7;j++){

if(el[i].clasa>el[j].clasa) {x=el[i]; el[i]=el[j];el[j]=x;}

cout<<"Ordonarea dupa clasa in ordine crescatoare : "<<endl<<endl;

afis(el);

cout<<endl<<endl;

//Clasa cu nota medie maxima:

int cl;

float med_clasa=0,med_tot=0,med_finala=0, med_partiala=0; int m=0;

for(int i=0;i<6;i++){

for(int j=i;j<7;j++){

if(el[i].clasa==el[j].clasa) {med_clasa=+el[i].nota_med; m++;}

med_partiala=med_clasa/m;

med_tot=med_partiala;

if (med_tot>med_finala) med_finala=med_tot;

}
cout<<"\n Media maxima de clasa este "<<med_finala;

return 0;