1

Topic: C on With ++

Hello, help to solve a problem. After start and data input, the program ceases to work, that is does not display result. What here it is made not so? In advance thanks for the answer.
The job:

 Progress of students. To write down in structure the following data about
Students: First name, middle initial, last name, No groups, estimations in 4 subjects. To organize a choice
Honors pupils. Selected to arrange alphabetically 


#include <iostream>
#include <string.h>
using namespace std;
int main ()
{
struct students
{
char* name;
int number;
int mark1;
int mark2;
int mark3;
int mark4;
};
students *student = new students ();
int k = 0;
cout <<"Vvedite kol-vo studentov:";
cin>> k;
for (int i = 0; i <k; i ++)
{
cout <<"\nVvedite imya studenta:";
cin>> student [i].name;
cout <<"\nVvedite nomer gruppi:";
cin>> student [i].number;
cout <<"\nVvedite ocenky po algebre:";
cin>> student [i].mark1;
cout <<"\nVvedite ocenky po fizike:";
cin>> student [i].mark2;
cout <<"\nVvedite ocenky po himii:";
cin>> student [i].mark3;
cout <<"\nVvedite ocenke po geografii:";
cin>> student [i].mark4;
}
students *excellentStudent = new students ();
int i = 0, n=0;
while (i <k)
{
if ((student [i].mark1 == 5) && (student [i].mark2 == 5) &&
(student [i].mark3 == 5) && (student [i].mark4 == 5))
{
excellentStudent [i] = student [i];
n ++;
}
i ++;
}
int choice = 0;
cout <<"\nVvedite ' 0 ', esli hotite otsortirovat po alfavity, \n"
"ili ' 1 ', esli sortirovka ne trebyetsya.";
cin>> choice;
do
{
switch (choice)
{
case 0:
students b;
for (int m = 0; m <(n - 1); m ++)
{
for (int a = (m + 1); a <n; a ++)
{
if (excellentStudent [m].name [0]> excellentStudent [a].name [0])
{
b = excellentStudent [m];
excellentStudent [m] = excellentStudent [a];
excellentStudent [a] = b;
}
}
}
for (int j = 0; j <n; j ++)
{
cout <<"\n\n [" <<j <<"]";
cout <<"\nImya studenta:" <<excellentStudent [j].name;
cout <<"\nNoper gruppi:" <<excellentStudent [j].number;
cout <<"\nOcenka po algebre:" <<excellentStudent [j].mark1;
cout <<"\nOcenka po fizike:" <<excellentStudent [j].mark2;
cout <<"\nOcenka po himii:" <<excellentStudent [j].mark3;
cout <<"\nOcenka po geometrii:" <<excellentStudent [j].mark4;
}
break;
case 1:
for (int j = 0; j <n; j ++)
{
cout <<"\n\n [" <<j <<"]";
cout <<"\nImya studenta:" <<excellentStudent [j].name;
cout <<"\nNomer gruppi:" <<excellentStudent [j].number;
cout <<"\nOcenka po algebre:" <<excellentStudent [j].mark1;
cout <<"\nOcenka po fizike:" <<excellentStudent [j].mark2;
cout <<"\nOcenka po himii:" <<excellentStudent [j].mark3;
cout <<"\nOcenka po geometrii:" <<excellentStudent [j].mark4;
}
break;
default:
cout <<"Vvedeno nevernoe znachenie ["
<<choice <<"]. Poprobuite snova.";
break;
}
} while ((choice == 0) || (choice == 1));
return 0;
}

2

Re: C on With ++

Avatangqa wrote:

help to solve a problem.

Step by step debugging helps you.

3

Re: C on With ++

Here:

struct students
{
char* name;
int number;
int mark1;
int mark2;
int mark3;
int mark4;
};
//...
cout <<"\nVvedite imya studenta:";
cin>> student [i].name;

Already there will be problems...
You understand, what do? You do not understand - use std:: string.

4

Re: C on With ++

Well and such here:

struct students
{
char* name;
int number;
int mark1;
int mark2;
int mark3;
int mark4;
};

The organization of structure of storage of estimations is on 2 points ().
Imagine that it is necessary to store not 4 estimations, and 100 estimations...

5

Re: C on With ++

MasterZiv wrote:

Well and such here:
The organization of structure of storage of estimations is on 2 points ().

Why, can  in indium smile there on 5 smile

6

Re: C on With ++

MasterZiv wrote:

Imagine that it is necessary to store not 4 estimations, and 100 estimations...

It is not necessary to multiply entities needlessly - old man Okkam)) spoke

7

Re: C on With ++

8

Re: C on With ++

Peter Sedov, the cool answer
From myself I will add: it is very difficult to work with pointers.  something somewhere goes not so.  for storage of a line to use std:: string, and for array storage - std:: vector (with a vector it will be like std:: vector <student> student_list ).
Here for example copying std:: string looks also, as copying of a normal variable. With pointers so it does not turn out. All these classes, and  all , are invented, that it was possible to simplify to itself the task (for complexity control).

9

Re: C on With ++

alexy_black wrote:

it is very difficult to work with pointers

Yes

10

Re: C on With ++

wrote:

it is passed...
Yes

So can it under the job on the contrary it is necessary.

11

Re: C on With ++

alexy_black wrote:

it is very difficult to work with pointers

+1. It is intolerable)))

12

Re: C on With ++

egorych wrote:

+1. It is intolerable)))

Specially for the decision of this problem and in due time language Java has been invented.

13

Re: C on With ++

14

Re: C on With ++

Dimitry Sibiryakov wrote:

Specially for the decision of this problem and in due time language Java has been invented.

shared_ptr has been for this purpose invented. And Java it is invented not to invent shared_ptr

Sedov wrote:

be simple can that the author of a question will study STL-containers in a following semester.

It, type how the brother from 6th class, on a question on the circle area to write integral from sqrt (r^2 - x^2) dx? [img=http://www.sql.ru/forum/images/happy.gif]

15

Re: C on With ++

Dimitry Sibiryakov wrote:

it is passed...
Specially for the decision of this problem and in due time language Java has been invented.

In modern With ++ with pointers practically it is not necessary to work, if you certainly do not write any
Device driver or library.

16

Re: C on With ++

MasterZiv wrote:

it is passed...
In modern With ++ with pointers practically it is not necessary to work, if you certainly do not write any
Device driver or library.

In as! And I also did not know that! And all in the old manner, with pointers... The Prana, classes and structures should be only static:)))

17

Re: C on With ++

nik_x wrote:

it is passed...
In as! And I also did not know that! And all in the old manner, with pointers... The Prana, classes and structures should be only static:)))

Well, study, develop...