Structured Data and Abstract Data Types Lab

Your Mission: Write a program that uses a structure to store the following data:

Member Name
Description
Name Student Name
Idnum Student ID Number
Tests Pointer to an array of test scores.
Average Average test score
Grade Course Grade

The program should keep a list of test scores for a group of students. It should ask the user how man tests scores there are to be and how many students there are. It should then dynamically allocate an array of structures to hold the student records. Each structure's Tests member should point to a dynamically allocated array which will hold the test scores.

After the arrays have been dynamically allocated, the program should ask for the ID number and all the test scores for each student. The average test score should be calculated and stored in the average member of each structure. The course grade should be computed, based on the following grading scale:

Average Test Grade Course Grade
91-100 A
81-90 B
71-80 C
61-70 D
60 or below E

The course grade should them be stored in the Grade member of each structure. Once all this data is calculated, a table should be displayed on the screen listing each student's name, ID number, average test score, and course grade.

Input Validation: Be sure all dat for each student is entered. Do not accept negative numbers for any test score.

Algorithmic suggestion: You can use this if you wish or go it alone.

// Name:
// Program Description

#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cstring>
using namespace std;

// Constants for arrays
const int NAME_SIZE = 45;

// Declaration of Student structure
struct Student
{

char name[NAME_SIZE]; // Student name
int idNum; // Student ID number
int *tests; // Pointer to array of test scores
double average; // Average test score
char grade; // Course grade

};

// Function prototypes
Student *initArrays(int, int);
void getInfo(Student [], int, int);
void showInfo(Student [], int, int);

int main()
{
int numStudents; // Number of students
int numTests; // Number of tests
Student *list; // Pointer to Student array

// Get the number of students.

// Get the number of tests per student.

// Create an array of Students
list = initArrays(numStudents, numTests);

// Populate the array with data.
getInfo(list, numStudents, numTests);

// Display the data.
showInfo(list, numStudents, numTests);
return 0;
}

//**************************************************
// Function initArrays *
// This function dynamically allocates an array *
// of Student structures and for each element in *
// the array, allocates an array of ints to hold *
// tests scors. The parameter s is the number of *
// element to allocate for the array of structures *
// and the parameter t is the number of elements *
// allocate for each array of ints. *
//**************************************************

Student *initArrays(int s, int t)
{
Student *ptr;

// Allocate the array of Student structures.
ptr = new Student[s];

// Allocate an array of ints (to hold test scores)
// for each element of the array of Student structures.
for (int count = 0; count < s; count++)
{
ptr[count].tests = new int[t];
}

// Return a pointer to the array of structures.
return ptr;
}

//*****************************************************
// Function getInfo *
// This function populates the Student array s with *
// data entered by the user. The paramater ns is the *
// number of students and nt is the number of tests. *
//*****************************************************

void getInfo(Student s[], int ns, int nt)
{
//define variables as needed

// Get the data for each student.

// Get the ID number.

// Get the test scores and accumulate a total.

// Calculate the average score.
s[index].average = static_cast<double>(total) / nt;

// Assign a letter grade.
i
}

//*****************************************************
// Function showInfo *
// This function displays all of the data in the *
// array s. The paramater ns is the number of *
// students and nt is the number of tests. *
//*****************************************************

void showInfo(Student s[], int ns, int nt)
{

//Define variables as needed.

//Use a for loop to step through the record structure and display the student information
}

Back to Top

! You are using a version 4 browser or older. If you are experiencing any problems with scrolling, please reload the page.