| vilgos | Дата: Вт, 14 Апр 2015, 20:39 | Сообщение # 1 |
 Старший программист
Группа: Модераторы
Сообщений: 76
Статус: Offline
| хед Код #pragma once
#include "targetver.h"
#include <stdio.h> #include <tchar.h> #include <iostream> #include <Windows.h> #include <conio.h> #include <time.h> #include <stdlib.h> #include <string>
using namespace std; код
Код #include "stdafx.h"
struct Student { string name; int age; float height; }; Student* init(){ Student *pV = new Student; cout << "Vvedite imya: "; cin >> pV->name; cout << "Vvedite vozrast: "; cin >> pV->age; cout << "Vvedite rost: "; cin >> pV->height; cout << "--------------------" << endl; return pV; } void printName(Student **pArr, int N){ for (int i = 0; i < N; i++){ cout << "Imya " << i + 1 << " student: " << pArr[i]->name << endl;
}
} void printAge(Student **pArr, int N){ for (int i = 0; i < N; i++){ cout << "Vozrast studenta " << pArr[i]->name << " - " << pArr[i]->age << endl;
} } void printHeight(Student **pArr, int N){ for (int i = 0; i < N; i++){ cout << "Rost studenta " << pArr[i]->name << " - " << pArr[i]->height << endl;
} } void print(Student **pArr, int N){ for (int i = 0; i < N; i++){ cout << "--------------------" << endl; cout << i + 1 << " student: " << endl; cout << pArr[i]->name << endl << pArr[i]->age << endl << pArr[i]->height << endl; cout << "--------------------" << endl; } } void erase(Student **pArr, int N) //очистка { for (int i = 0; i < N; i++){ delete pArr[i]; } } int main() { cout << "Vvedite kolichestvo studentov: "; int N = 0; cin >> N; Student **pArr = new Student*[N]; for (int i = 0; i < N; i++){ pArr [i]= init(); } cout << "Chto vivodit'?(1-imena, 2-vozrast, 3-rost, 0-vse): "; int k = 0; cin >> k; switch (k) { case 1: printName(pArr, N); break; case 2: printAge(pArr, N); break; case 3: printHeight(pArr, N); break; case 0: print(pArr, N); break; default: break; } erase(pArr, N);
_gettch(); return 0; } Код #include "stdafx.h"
struct Student { string name; int age; float height; }; Student* init(){ Student *pV = new Student; cout << "Vvedite imya: "; cin >> pV->name; cout << "Vvedite vozrast: "; cin >> pV->age; cout << "Vvedite rost: "; cin >> pV->height; cout << "--------------------" << endl; return pV; } void printName(Student **pArr, int N){ for (int i = 0; i < N; i++){ cout << "Imya " << i + 1 << " student: " << pArr[i]->name << endl;
}
} void printAge(Student **pArr, int N){ for (int i = 0; i < N; i++){ cout << "Vozrast studenta " << pArr[i]->name << " - " << pArr[i]->age << endl;
} } void printHeight(Student **pArr, int N){ for (int i = 0; i < N; i++){ cout << "Rost studenta " << pArr[i]->name << " - " << pArr[i]->height << endl;
} } void print(Student **pArr, int N){ for (int i = 0; i < N; i++){ cout << "--------------------" << endl; cout << i + 1 << " student: " << endl; cout << pArr[i]->name << " " << pArr[i]->age << " " << pArr[i]->height << endl; cout << "--------------------" << endl; } } //void print2(Student **pArr, int N,int age){ // for (int i = 0; i < N; i++){ // if (pArr[i]->age < age){ // cout << "--------------------" << endl; // cout << i + 1 << " student: " << endl; // cout << pArr[i]->name << endl << pArr[i]->age << endl << pArr[i]->height << endl; // cout << "--------------------" << endl; // } // } //} void ssort(Student **pArr,int N){ for (int i = 0; i < N-1; i++){ string s = pArr[i]->name; char mass[20]; strcpy_s(mass, s.c_str()); string s2 = pArr[i+1]->name; char mass2[20]; strcpy_s(mass2, s2.c_str()); if (mass[0]>mass2[0]){ Student *v = new Student; v=pArr[i]; pArr[i]= pArr[i + 1]; pArr[i + 1]= v; //delete v; i = - 1; } } } void erase(Student **pArr, int N) //очистка { for (int i = 0; i < N; i++){ delete pArr[i]; } } int main() { cout << "Vvedite kolichestvo studentov: "; int N = 0; cin >> N; Student **pArr = new Student*[N]; for (int i = 0; i < N; i++){ pArr [i]= init(); } /*cout << "skol'ko vivesti?: "; int k = 0; cin >> k; print(pArr, k);*/ /*cout << "Chto vivodit'?(1-imena, 2-vozrast, 3-rost, 0-vse): "; int k = 0; cin >> k; switch (k) { case 1: printName(pArr, N); break; case 2: printAge(pArr, N); break; case 3: printHeight(pArr, N); break; case 0: print(pArr, N); break; default: break; }*/ /*cout << "mladshe kakogo vozrasta?: "; int age = 0; cin >> age; print2(pArr, N, age);*/ cout << "skol'ko studentov dobavit'?: "; int K = 0; cin >> K; print(pArr, N); int b = N + K; Student **pArr2 = new Student*[b]; for (int i = 0; i < N; i++){ pArr2 [i]= pArr[i]; }
for (int i = N; i < b; i++){ pArr2 [i]= init(); } ssort(pArr2, b); print(pArr2, b);
erase(pArr2, b); _gettch(); return 0; }
|
| |
|
|