An array stores details of 25 students (rollno, name, marks in 3 subjects). Write a program in C++ to create such an array and print out a list of students who have failed in more than one subject. Assume 40% as pass marks.
1
Expert's answer
2012-12-05T09:46:27-0500
# include <iostream> # include <string> using namespace std; class stud{ char *rollno; char *name; double m[3]; public: stud(){} ~stud(){delete [] name; delete [] rollno;} void get(){ & name = new char [20]; & rollno = new char [15]; & & cout<<"enter name: "; & cin.getline(name,20,'\n'); & cout<<"enter rollno: "; & cin.getline(rollno,15,'\n'); & for(int i=0;i<3;i++){ & cout<<"enter mark"<<i<<": "; & cin>>m[i]; & } & cin.ignore(); } void out(){ & int t(0); & if (m[0]<40) t++; & if (m[1]<40) t++; & if (m[2]<40) t++; & if (t>=2) put(); } void put(){ & cout<<name<<" "<<rollno<<endl; } };
int main(){ const int num=2; stud a[25]; cout<<"At first enter 25 students!\n"; for (int i=0;i<num;i++){ & a[i].get(); } cout<<"failed students:\n"; for (int i=0;i<num;i++){ & a[i].out(); }
An array stores details of 5 students(rollno, name, marks in three
subjects). write a program to create such an array and print out a
list of students who have failed in more than one subjects. Assume 40%
as pass marks. Use array of structures with functions.
Comments
Dear visitor, please use panel for new questions
An array stores details of 5 students(rollno, name, marks in three subjects). write a program to create such an array and print out a list of students who have failed in more than one subjects. Assume 40% as pass marks. Use array of structures with functions.