0% found this document useful (0 votes)
160 views10 pages

POO Lab 1

The document describes a C++ program that uses structures to store information about companies. It defines a Firm structure with fields for name, organization type, address, and age. The program allows the user to add, view, update, and search for firms in an array of Firm structures. Functions are defined to handle each task: AddFirm adds a new structure, ViewFirm displays all structures, UpdateFirm modifies an existing one, and SearchFirm finds a structure by different fields. The main function runs a menu loop calling these functions until the user exits.

Uploaded by

Wolf4eNNoK
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)
160 views10 pages

POO Lab 1

The document describes a C++ program that uses structures to store information about companies. It defines a Firm structure with fields for name, organization type, address, and age. The program allows the user to add, view, update, and search for firms in an array of Firm structures. Functions are defined to handle each task: AddFirm adds a new structure, ViewFirm displays all structures, UpdateFirm modifies an existing one, and SearchFirm finds a structure by different fields. The main function runs a menu loop calling these functions until the user exits.

Uploaded by

Wolf4eNNoK
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 de Calculatoare, Informatică si Microelectronică

Lucrare de laborator Nr1

Disciplina:”Programarea in limbajul C++”


Tema:„Structura-mecanism de abstractizare”

A efectuat: st. gr. MI-191


. Zmeu Vitalie
A verificat: prof. conf. univ.
. Mamolea Igor

Chișinău-2020
#include <iostream>
#include<string.h>

using namespace std;

struct Firm
{
char name[50];
char organization[50];
char adress[50];
int age;
} f[100];

int n = 0;

void AddFirm(){
cout << "Adaugare firma: " << endl;
cout << "Denumirea: ";
cin >> f[n].name;
cout << "Forma de organizare: ";
cin >> f[n].organization;
cout << "Adresa firmei: ";
cin >> f[n].adress;
cout << "Anul fondarii: ";
cin >> f[n].age;
cout << endl << endl;
n++;
}

void ViewFirm(){
cout << "Sunt introduse "<< n << " firme." << endl;
if(n != 0)
for(int i = 0; i < n; i++){
cout << "Numarul in lista : "<< i << endl;
cout << f[i].name << " ";
cout << f[i].organization << " ";
cout << f[i].adress << " ";
cout << f[i].age << endl;
}
else cout << "Lista nu a fost completata!" << endl;
cout << endl << endl;
}

void SearchFirm(){
int ch;
char c[50];
cout << "Alegeti metoda de cautare:\n";
cout << "1 - Denumire.\n";
cout << "2 - Forma de organizare.\n";
cout << "3 - Adresa.\n";
cout << "4 - Anul de fondare.\n";
cout << "::: ";
cin >> ch;

switch(ch){
case 1:{
cout << "Introduceti denumirea firmei cautate: ";
cin >> c;
cout << endl << endl;
for(int i = 0; i < n; i++)
if(strcmp(f[i].name, c) == 0){
cout << "Numarul in lista : "<< i << endl;
cout << f[i].name << " ";
cout << f[i].organization << " ";
cout << f[i].adress << " ";
cout << f[i].age << endl;
}
break;
}

case 2:{
cout << "Introduceti forma de organizare a firmei cautate: ";
cin >> c;
cout << endl << endl;
for(int i = 0; i < n; i++)
if(strcmp(f[i].organization, c) == 0){
cout << "Numarul in lista : "<< i << endl;
cout << f[i].name << " ";
cout << f[i].organization << " ";
cout << f[i].adress << " ";
cout << f[i].age << endl;
}
break;
}

case 3:{
cout << "Introduceti adresa firmei cautate: ";
cin >> c;
cout << endl << endl;
for(int i = 0; i < n; i++)
if(strcmp(f[i].adress, c) == 0){
cout << "Numarul in lista : "<< i << endl;
cout << f[i].name << " ";
cout << f[i].organization << " ";
cout << f[i].adress << " ";
cout << f[i].age << endl;
}
break;
}

case 4:{
cout << "Introduceti anul fondarii firmei cautate: ";
int x;
cin >> x;
cout << endl << endl;
for(int i = 0; i < n; i++)
if(f[i].age == x){
cout << "Numarul in lista : "<< i << endl;
cout << f[i].name << " ";
cout << f[i].organization << " ";
cout << f[i].adress << " ";
cout << f[i].age << endl;
}
break;
}
}
cout << endl << endl;
}

void UpdateFirm(){
int x;
char c[50];
char q[] = "-";
int z;
cout << "Introduceti nr de ordine a firmei in lista(Incepind cu 0):";
cin >> x;
cout << "Denumirea:\n";
cout << f[x].name << " ";
cin >> c;
if(strcmp(c, q) != 0) strcpy(f[x].name, c);
cout << "Forma de organizare:\n";
cout << f[x].organization << " ";
cin >> c;
if(strcmp(c, q) != 0) strcpy(f[x].organization, c);
cout << "Adresa:\n";
cout << f[x].adress << " ";
cin >> c;
if(strcmp(c, q) != 0) strcpy(f[x].adress, c);
cout << "Anul:\n";
cout << f[x].age << " ";
cin >> f[x].age;
}

int main(){
int choice;

do{
cout << "Menu: \n";
cout << "1 - Adaugarea unei firme in lista. \n";
cout << "2 - Afisarea listei introduse. \n";
cout << "3 - Modificarea datelor unei firme. \n";
cout << "4 - Afisarea unei firme. \n";
cout << "5 - Exit!\n";
cout << "::: ";
cin >> choice;

cout << endl << endl;

switch (choice){
case 1:
AddFirm();
break;
case 2:
ViewFirm();
break;
case 3:
UpdateFirm();
break;
case 4:
SearchFirm();
break;
case 5:
break;
default:
cout << "Not a Valid Choice. \n" << "Choose again.\n";
cout << endl << endl;
break;
}

}while (choice !=5);


return 0;
}

You might also like