- Write a program that reads student information (first name, last name, NID, and test score) and displays all of the students with scores below a requested cutoff score.
- The program must first request the number of students in the class. Validate the entry to accept only integers from 0 to 100.
- The student information must be stored in a struct with the following form:
student[].name.first
student[].name.last
student[].nid
student[].score
- The program must request all the student information on a student-by-student basis.
- The first name must be validated to only accept lowercase and uppercase letters (limited to 30 characters).
- The last name must be validated to only accept lowercase and uppercase letters (limited to 30 characters).
- The NID must be validated to only accept lowercase letters and numbers (limited to 30 characters).
- The score must be validated to only accept integers from 0 to 100.
- The program must then request a cutoff score (validated as an integer from 0 to 100) and display all the information for students with scores below the cutoff.
- The number of students, first name, last name, NID, score, and cutoff score, as well as the student information display must be done through four different functions with prototypes as shown below:
bool GetString(char []);
bool GetNID(char []);
bool GetScore(int *);
void DisplayStudent(StudentData);
Here is what i have:
#include <iostream>
#include <cstdlib>
using namespace std;
struct NameType
{
char first[30];
char last[30];
};
struct StudentType
{
NameType name;
int age;
char nid[10];
float score;
};
void main()
{
StudentType student[100];
float AveAge = 0.0;
float AveSco = 0.0;
int i,nStudents;
do
{
cout << "Enter the number of students [1-100]: ";
cin >> nStudents;
if ((nStudents < 1) || (nStudents > 100))
{
cout << "Incorrect value. Try again... " << endl;
}
} while ((nStudents < 1) || (nStudents > 100));
for (i=0;i<nStudents;i++)
{
cout << "Enter information for Student #" << i+1 << endl;
cout << " First name: ";
cin >> student[i].name.first;
cout << " Last name: ";
cin >> student[i].name.last;
cout << " Age: ";
cin >> student[i].age;
cout << " NID: ";
cin >> student[i].nid;
cout << " Grade: ";
cin >> student[i].score;
}
for (i=0;i<nStudents;i++)
{
AveAge = AveAge + student[i].age;
AveSco = AveSco + student[i].score;
}
AveAge = AveAge / nStudents;
AveSco = AveSco / nStudents;
cout << "First name, Last name, Age, NID, and Grade" << endl;
for (i=0;i<nStudents;i++)
{
cout << student[i].name.first << " ";
cout << student[i].name.last << " ";
cout << student[i].age << " ";
cout << student[i].nid << " ";
cout << student[i].score << endl;
}
cout << "The average student age is: " << AveAge << endl;
cout << "The average student grade is: " << AveSco << endl;
}
This post has been edited by Dark_Nexus: 21 November 2006 - 11:05 AM

New Topic/Question
Reply




MultiQuote




|