The code says bad, you have to figure out exactly what you're writing - C, C+ or C+++ - it's a joke. When the code is written on the plus plus, but it's the best.Why is the error in the removal of the clots?Look at your code.for(i=0; i<n; i++)
for(j=0; j<4; j++)
if(box[i].ocenka[j] == 3)
delete [] box[i];
If the first estimate is triple, the second evaluation will be a mess. Because the element is already removed. That's not right. But the problem is, you can't get away with the usual mass. It's not a vector. But if you have to remove all the non-trailers, you don't have to remove them. You can just miss it. In your case, it'll be easier.Well, I'd like to hear what kind of punks go into the eye.The scariest thing that leaves is the following lines.#include <Windows.h>
#include <conio.h>
The first is definitely not necessary, and the second is for ancient compilators.I sorted the code a little, and now it's a clean computer.#include <string.h>
#include <stdlib.h>
#include <stdio.h>
const int n=2;
struct ZACHETKA
{
char last_name[30];
int no;
int ocenka[3];
};
int main()
{
/*
Фамилия студента
Номер зачетки
Массив из 4 оценок
Сортировка структур по фамилии или среднему баллу
Удаление всех зачеток троечников
*/
int j,i;
struct ZACHETKA* box = (struct ZACHETKA*)malloc(sizeof(struct ZACHETKA) * n);
struct ZACHETKA tmp;
for(i=0; i<n; i++)
{
puts("Vvedite Familiy\n");
scanf("%s", box[i].last_name);
puts("Vvedite nomer\n");
scanf("%d", &box[i].no);
puts("Vvedite ocenki (3)\n");
scanf("%d %d %d", &box[i].ocenka[0], &box[i].ocenka[1], &box[i].ocenka[2]);
}
//- Cортировка по фамилии
for(i=n-1; i>0 ; i--)
for(j=0; j<i ; j++)
if(strcmp( box[ j ].last_name, box[ j+1 ].last_name ) > 0)
{
tmp = box[ j ];
box[ j ]= box[ j+1 ];
box[ j+1 ]= tmp;
}
for(i=0; i<n; i++)
{
for (int j = 0; j < 3; j++) {
if (box[i].ocenka[j] == 3)
goto fin; // да, в данном случае это оправдано, это си
}
printf("%s\n", box[i].last_name);
printf("%d\n", box[i].no);
for(j=0; j<3; j++)
printf("%d ", box[i].ocenka[j]);
printf("\n");
fin:;
}
free(box);
return 0;
}
I thought I'd clean up a little code and move it to a more plugged sie. I'd say it's one and a half plus.#include <string>
#include <iostream>
#include <vector>
const int max_number_of_students=2;
const int grades_count = 3;
struct RecordBook // да, так будет зачетка
{
std::string last_name;
int no;
int grades[grades_count]; // раньше это называлось "ocenka"
};
int main()
{
/*
Фамилия студента
Номер зачетки
Массив из 4 оценок
Сортировка структур по фамилии или среднему баллу
Удаление всех зачеток троечников
*/
std::vector<RecordBook> box;
RecordBook t;
for(int i = 0; i < max_number_of_students; i++)
{
std::cout << "Enter Last Name:" << std::endl;
getline(std::cin, t.last_name);
std::cout << "Enter Nomer:" << std::endl;
std::cin >> t.no;
std::cout << "Enter grades (count:"<< grades_count <<")" << std::endl;
for (int j = 0; j < grades_count; j++)
std::cin >> t.grades[j];
// почему эта строка ниже - http://modwind.ru/publ/cpp_io_input_output_advice/6-1-0-7
std::cin.ignore(50, '\n');
box.push_back(t);
}
//- Cортировка по фамилии
// Здесь хорошо бы применить стандартный алгоритм сортировки, но боюсь это будет перебор.
for(size_t i=box.size()-1; i>0 ; i--)
for(size_t j=0; j<i ; j++)
if(box[ j ].last_name > box[ j+1 ].last_name)
{
std::swap(box[j], box[j+1]);
// три строки ниже - олд-скул вариант.
//RecordBook t = box[j];
//box[j] = box[j+1];
//box[j+1] = t;
}
for(size_t i=0; i<box.size(); i++)
{
bool is_find = false;
for (int j = 0; j < grades_count; j++) {
if (box[i].grades[j] == 3) {
is_find = true;
break;
}
}
if (is_find)
continue;
std::cout << box[i].last_name << std::endl << box[i].no << std::endl;
for(int j=0; j<grades_count; j++)
std::cout << box[i].grades[j] << " ";
std::cout << std::endl;
}
return 0;
}
The code is slightly garried, translite has been relayed to a greater degree of English, and many magic numbers have been made to the stables. The number of students that need to be introduced is now only assigned in one place and it's easy to change. A lot of changes I'd make, I didn't turn it on.