1.

(a) Write a C++ program to store and print information (name, roll and marks) of a student using structure.(b) Write a program in C++ to input the total marks obtained by a group of students in a class and display them in descending order using pointer.

Answer»

(a) #include<iostream>

using namespace std;

int main()

{

struct student

{

char name[40];

int roll;

int marks[6];

}
S1;

count<<"Enter name";

cin>>S1.name;

cout<<"Enter roll no";

cin>>S1.roll;

cout<<"Enter 6 marks";

for (int i=0;i<6;i++)

cin>>S1.marks[i];

cout<<"The details are given below";

cout<<"\n Name:"<<S1.name;

cout<<"\n Roll No:"<<S1.roll;

for (int i=0;i<6;i++)

cout<<"\n mark"<<i + 1<<S1.marks[i];

return 0;

}

(b) #include<iostream>

using namespace std;

int main ()

{

int main [50],i,j,*ptr,n,temp, ptr = mark;

cout<<"Enter how many student";

cin>>n;

for(i=0;i<n;i++)

{

cout<<"Enter mark"<<i+1<<";";

cin>>*(ptr++)

}

for(i=0;i<n-1;i++)

for(j=i+1;j<n;j++)

if(mark[i]>mark[j])

{

temp = mark[i];

mark[i] = mark[j];

mark[j] = temp;

} ptr = mark;

cout<<"The marks in descending order";

for(i=0;j<n;i++)

cout<<*(ptr++)<<endI;

}



Discussion

No Comment Found