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
13 Answers
0
it's actually string but there was not enough sapce in question was I write it small
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
0
it's not working
0
where???
0
I put that in compiler it's saying "no output"
which means code is right????
0
thank you very much Timon
- 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.
- 1
Ok, then you have the same order than with char arrays.
- 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()
{
}
- 1
Fixed, forgot ; after the struct.
- 1
float cgpa;
} /*here*/ ;
- 1
Yes, now it's right. The semicolon after /*here*/ was missing until I fixed it.
- 1
No problem, that's why I'm here.