using namespace std; struct student{ int roll; char name[30]; char fname[30]; float cgpa; } s[10]; int main (void) { } | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

using namespace std; struct student{ int roll; char name[30]; char fname[30]; float cgpa; } s[10]; int main (void) { }

can anyone make this structure in descending order

13th Dec 2017, 7:53 PM
Rehan Solangi
Rehan Solangi - avatar
13 Answers
0
it's actually string but there was not enough sapce in question was I write it small
14th Dec 2017, 6:43 AM
Rehan Solangi
Rehan Solangi - avatar
0
#include <iostream> #include <string> using namespace std; struct student{ int roll; char name[30]; char fname[30]; float cgpa; } s[10]; int main (void) { } this is real structure and now I have put a code so this can come in descending order
14th Dec 2017, 6:57 AM
Rehan Solangi
Rehan Solangi - avatar
0
it's not working
14th Dec 2017, 7:21 AM
Rehan Solangi
Rehan Solangi - avatar
0
where???
14th Dec 2017, 7:33 AM
Rehan Solangi
Rehan Solangi - avatar
0
I put that in compiler it's saying "no output" which means code is right????
14th Dec 2017, 7:37 AM
Rehan Solangi
Rehan Solangi - avatar
0
thank you very much Timon
14th Dec 2017, 7:48 AM
Rehan Solangi
Rehan Solangi - avatar
- 1
Like this? struct student { //char arrays first char name[30]; char fname[30]; //int and float second (they have the same size most often) int roll; float cgpa; } Why do you use a char[30] instead of a std::string? And did you know that if you really don't want to use strings you can make the first char[30] a char[32] since most devices have adress rooms which take 2 to the power of n bytes? Btw Bjarne Stroustrup, the inventor of c++, says that you should order your structs in an intuitive order and not by size if performance is not really critical.
14th Dec 2017, 6:29 AM
Timon Paßlick
- 1
Ok, then you have the same order than with char arrays.
14th Dec 2017, 6:46 AM
Timon Paßlick
- 1
I'd do it like #include <iostream> #include <string> #include <array> using namespace std; struct student { string fname; string name; int roll; float cgpa; }; array<student, 10> s; int main() { }
14th Dec 2017, 7:06 AM
Timon Paßlick
- 1
Fixed, forgot ; after the struct.
14th Dec 2017, 7:28 AM
Timon Paßlick
- 1
float cgpa; } /*here*/ ;
14th Dec 2017, 7:34 AM
Timon Paßlick
- 1
Yes, now it's right. The semicolon after /*here*/ was missing until I fixed it.
14th Dec 2017, 7:47 AM
Timon Paßlick
- 1
No problem, that's why I'm here.
14th Dec 2017, 7:49 AM
Timon Paßlick