C++ Program to read, print name and other details of 50 students ? Problem Statement : The annual examination is conducted for 50 students for three subjects. Write a program to read the data and determine the following: (a) Total marks obtained by each student. (b) The highest marks in each subject and the Roll No. of the student who secured it. (c) The student who obtained the highest total marks. (d) Prevents accepting from another data type with out their type.

Q1.Write a program to enter no. of students , each student have 4 subjects then find the number of pass and fail subjects for each student .

Sure! Here's how you can implement the program step-by-step in C++:

Step 1: Include the necessary header files
```cpp
#include <iostream>
#include <string>
using namespace std;
```

Step 2: Declare the structure to store student details
```cpp
struct Student {
string name;
int rollNo;
int marks[3]; // marks for three subjects
int totalMarks;
};
```

Step 3: Define functions to perform required operations

(a) Function to calculate total marks obtained by each student
```cpp
void calculateTotalMarks(Student& student) {
student.totalMarks = 0;
for (int i = 0; i < 3; i++) {
student.totalMarks += student.marks[i];
}
}
```

(b) Function to find the highest marks in each subject and the Roll No. of the student who secured it
```cpp
void findHighestMarks(Student* students, int numStudents) {
int highestMarks[3] = {0}; // initialize with 0
int highestRollNo[3] = {0}; // initialize with 0

for (int i = 0; i < numStudents; i++) {
for (int j = 0; j < 3; j++) {
if (students[i].marks[j] > highestMarks[j]) {
highestMarks[j] = students[i].marks[j];
highestRollNo[j] = students[i].rollNo;
}
}
}

for (int i = 0; i < 3; i++) {
cout << "Highest marks in subject " << i+1 << ": " << highestMarks[i] << endl;
cout << "Roll No. of the student who secured it: " << highestRollNo[i] << endl;
}
}
```

(c) Function to find the student who obtained the highest total marks
```cpp
void findHighestTotalMarks(Student* students, int numStudents) {
int highestTotalMarks = 0;
int highestTotalMarksRollNo = 0;

for (int i = 0; i < numStudents; i++) {
if (students[i].totalMarks > highestTotalMarks) {
highestTotalMarks = students[i].totalMarks;
highestTotalMarksRollNo = students[i].rollNo;
}
}

cout << "Student who obtained the highest total marks:" << endl;
cout << "Roll No.: " << highestTotalMarksRollNo << endl;
cout << "Total Marks: " << highestTotalMarks << endl;
}
```

(d) Function to validate input type
```cpp
void validateInput(int& input) {
while (cin.fail()) {
cin.clear();
cin.ignore(100, '\n');
cout << "Invalid input. Please enter an integer: ";
cin >> input;
}
}
```

Step 4: Implement the main function
```cpp
int main() {
const int numStudents = 50;
Student students[numStudents];

// Read student details
for (int i = 0; i < numStudents; i++) {
cout << "Enter details for student " << i+1 << ":" << endl;
cout << "Name: ";
cin >> students[i].name;
cout << "Roll No.: ";
cin >> students[i].rollNo;
validateInput(students[i].rollNo); // Validate roll No. input type

for (int j = 0; j < 3; j++) {
cout << "Marks for subject " << j+1 << ": ";
cin >> students[i].marks[j];
validateInput(students[i].marks[j]); // Validate marks input type
}

calculateTotalMarks(students[i]);
}

// Calculate total marks, find highest marks, and find student with highest total marks
findHighestMarks(students, numStudents);
findHighestTotalMarks(students, numStudents);

return 0;
}
```

That's it! This program will allow you to read, print the name and other details of 50 students, and determine the total marks obtained by each student, the highest marks in each subject, the Roll No. of the student who secured it, and the student who obtained the highest total marks in the three subjects.

To solve this problem, you can use a struct to represent the student's details and create an array of 50 students. Here's an example C++ program that reads and prints the name and other details of 50 students, as well as solves the additional tasks mentioned in the problem statement:

```cpp
#include <iostream>
#include <limits> // For handling invalid input

// Struct to represent student's details
struct Student {
int rollNo;
std::string name;
int marks[3]; // Array to store marks for three subjects
int totalMarks; // Variable to store total marks
};

int main() {
const int numStudents = 50;
Student students[numStudents];

// Read details of each student
for (int i = 0; i < numStudents; ++i) {
std::cout << "Enter details for student #" << i + 1 << ":" << std::endl;

// Read roll no
std::cout << "Roll No: ";
while (!(std::cin >> students[i].rollNo)) {
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cout << "Invalid input. Please enter an integer value for Roll No: ";
}

// Read name
std::cout << "Name: ";
std::cin.ignore();
std::getline(std::cin, students[i].name);

// Read marks for three subjects
for (int j = 0; j < 3; ++j) {
std::cout << "Marks for Subject " << j + 1 << ": ";
while (!(std::cin >> students[i].marks[j])) {
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cout << "Invalid input. Please enter an integer value for marks: ";
}

students[i].totalMarks += students[i].marks[j];
}

std::cout << std::endl;
}

// Calculate and print total marks for each student
std::cout << "Total marks obtained by each student:" << std::endl;
for (int i = 0; i < numStudents; ++i) {
std::cout << "Student #" << i + 1 << ": " << students[i].totalMarks << " marks" << std::endl;
}
std::cout << std::endl;

// Find the highest marks in each subject and the Roll No. of the student who secured it
int highestMarks[3] = {0};
int highestMarksRollNo[3] = {0};
for (int i = 0; i < numStudents; ++i) {
for (int j = 0; j < 3; ++j) {
if (students[i].marks[j] > highestMarks[j]) {
highestMarks[j] = students[i].marks[j];
highestMarksRollNo[j] = students[i].rollNo;
}
}
}

std::cout << "Highest marks in each subject:" << std::endl;
for (int j = 0; j < 3; ++j) {
std::cout << "Subject " << j + 1 << ": " << highestMarks[j] << " marks (Student #" << highestMarksRollNo[j] << ")" << std::endl;
}
std::cout << std::endl;

// Find the student who obtained the highest total marks
int highestTotalMarks = 0;
int highestTotalMarksRollNo = 0;
for (int i = 0; i < numStudents; ++i) {
if (students[i].totalMarks > highestTotalMarks) {
highestTotalMarks = students[i].totalMarks;
highestTotalMarksRollNo = students[i].rollNo;
}
}

std::cout << "Student who obtained the highest total marks:" << std::endl;
std::cout << "Student #" << highestTotalMarksRollNo << ": " << highestTotalMarks << " marks" << std::endl;

return 0;
}
```

Explanation:
1. The program starts by defining a struct called `Student` that holds the student's details such as roll no, name, marks for three subjects, and total marks.
2. Inside the `main` function, an array of 50 students is declared.
3. A loop is used to read the details for each student. The user is prompted to enter the roll no, name, and marks for three subjects. Input validation is performed to handle invalid input (e.g., non-integer roll no or marks).
4. The total marks for each student are calculated by iterating over the marks array and accumulating them into the `totalMarks` variable.
5. After reading all the details, the program proceeds to solve the additional tasks mentioned in the problem statement.
6. To calculate the total marks obtained by each student, another loop is used to iterate over the array of students and print their total marks.
7. To find the highest marks in each subject and the corresponding roll no, two arrays (`highestMarks` and `highestMarksRollNo`) are used. Another nested loop is used to iterate over the marks of each student and update the highest marks and roll no if necessary.
8. The program then prints the highest marks in each subject along with the corresponding roll no.
9. To find the student who obtained the highest total marks, a similar logic is used with a predefined variable `highestTotalMarks` and `highestTotalMarksRollNo`. Another nested loop is used to iterate over the students and update the variables if a higher total marks value is found.
10. Finally, the program prints the roll no and total marks of the student who obtained the highest total marks.

Please note that the solution assumes the user will enter valid input as per the problem statement requirements (e.g., 50 students' data with appropriate data types). However, input validation is implemented to prevent accepting invalid input for the roll no and marks.