Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication12.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- struct peopleData {
- char sex[2];
- int varsta;
- float greutate, inaltime;
- };
- peopleData people[128];
- int n;
- void inputData(peopleData people[], int n) {
- for (int i = 1; i <= n; i++) {
- cout << "Introdu sexul persoanei " << i << ": ";
- cin.get(people[i].sex, 2);
- cin.get();
- cout << endl;
- cout << "Introdu varsta persoanei " << i << ": ";
- cin >> people[i].varsta;
- cout << endl;
- cout << "Introdu greutatea persoanei " << i << ": ";
- cin >> people[i].greutate;
- cout << endl;
- cout << "Introdu inaltimea persoanei " << i << ": ";
- cin >> people[i].inaltime;
- cout << endl;
- }
- }
- int globalMb, globalMg, globalM, globalF;
- void percent(peopleData people[], int n) {
- int male = 0, female = 0;
- for (int i = 1; i <= n; i++) {
- if (people[i].sex == "M") male++;
- else female++;
- }
- globalM = male;
- globalF = female;
- int perc = (male / n) * 100;
- cout << "Procentajul barbatilor este de " << perc << " iar cel al femeilor este de " << 100 - perc << endl;
- }
- void medAge(peopleData people[], int n) {
- int mg = 0, sb = 0, male = 0, mb = 1;
- for (int i = 1; i <= n; i++) {
- mg += (people[i].varsta);
- if (people[i].sex == "M")
- {
- sb += (people[i].varsta);
- male++;
- }
- }
- globalMg = mg;
- mb = sb / male;
- cout << "Varsta medie a grupului este: " << mg/n << " iar a barbatilor: " << mb << ". \n";
- }
- void percFemMale(peopleData people[], int n) {
- int countFem = 0, countMale = 0;
- for (int i = 1; i <= n; i++) {
- if (people[i].sex == "M" && people[i].varsta > globalMg) countMale++;
- else if (people[i].sex == "F" && people[i].varsta > globalMg) countFem++;
- }
- int percFem = (countFem / n) * 100;
- cout << "Procentul de femei este: " << percFem << " iar cel de barbati este: " << 100 - percFem;
- }
- void medHeight(peopleData people[], int n) {
- int hM = 0, hFem = 0;
- for (int i = 1; i <= n; i++) {
- hM += (people[i].inaltime);
- if (people[i].sex == "F")
- hFem += people[i].inaltime;
- }
- float hFemMed = hFem / globalF;
- float hMedG = hM / n;
- cout << "Inaltimea medie a grupului este: " << hMedG << " iar a femeilor este: " << hFemMed << endl;
- int countFem = 0, countMale = 0;
- for (int i = 1; i <= n; i++) {
- if (people[i].sex == "M" && people[i].inaltime > hMedG) countMale++;
- else if (people[i].sex == "F" && people[i].inaltime > hMedG) countFem++;
- }
- int percFem = (countFem / n) * 100;
- cout << "Procentul de femei este: " << percFem << " iar cel de barbati este: " << 100 - percFem;
- }
- void medWeight(peopleData people[], int n) {
- int groupWeight = 0, maleWeight = 0, femWeight = 0;
- for (int i = 1; i <= n; i++) {
- groupWeight += people[i].greutate;
- if (people[i].sex == "M")
- maleWeight += people[i].greutate;
- else femWeight += people[i].greutate;
- }
- cout << "Greutatea medie a grupului: " << groupWeight / n << " , cea a femeilor: " << femWeight / globalF << " iar cea a barbatilor: " << maleWeight / globalM;
- int countFem = 0, countMale = 0;
- for (int i = 1; i <= n; i++) {
- if (people[i].sex == "M" && people[i].greutate > groupWeight / n) countMale++;
- else if (people[i].sex == "F" && people[i].greutate > groupWeight / n) countFem++;
- }
- int percFem = (countFem / n) * 100;
- cout << "Procentul de femei este: " << percFem << " iar cel de barbati este: " << 100 - percFem;
- }
- int main()
- {
- cout << "Mentioneaza numarul de persoane: ";
- cin >> n;
- inputData(people, n);
- percent(people, n);
- medAge(people, n);
- percFemMale(people, n);
- medHeight(people, n);
- medWeight(people, n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement