Sorry this is so long but I'm really stuck. Some parts of my code are not working and I don't know why. The first, second, and third parts are correct but I'm having problems with all the parts after that. There is a bunch of code at the bottom in green that I wrote out, trying to figure out the five parts that are incomplete. If it's correct, where should it go? If it's incorrect, how should it look? I also don't really know what to do for the sixth, seventh, and eighth parts. And if it's not too much trouble, could you write out the code so I can see how it should look? If anyone is willing to help, it would be greatly appreciated.
First part:
Create a structure type called "Student" with the following properties
-first name
-last name
-age
-student number
-grade
Second part:
Create a structure type called "klass" with the following properties
-array of students
-size of class
-name of class
-last name of teacher
-period of the day
Third part:
Create a function called "create student" which takes as parameters all the characteristics of a student. It should return a student with the appropriate values.
Example: student1 ("Eric", "Cartman", 16, 803612, 10);
Forth part:
Create a function called "add student to class" which accepts as parameters a student and a class. The function should add the student to the array of student of the specific class.
Example: addstudenttoclass (student1, class1);
Fifth part:
Write a function called "display student" that accepts a student as parameters. This function should display the properties of the student.
Sixth part:
Write a function that searches a class for a given student. The function should accept a string representing the student's last name and return an integer representing in the class's array where the student is stored. If the student is not in the class it should return a value of -1.
Seventh part:
Write a function that will remove a student from a "klass". The function should accept as parameter a "klass" and either a student, a first name, or an integer. The function should return a "klass".
Eighth part:
Write a series of functions that will serve as an interface for your functions. Do not modify your previously constructed functions.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
struct student{
char lastname[30]; // Student's first name/max 30 characters
char firstname[30]; // Student's first name/max 30 characters
int age; // Student's age
int studentnumber; // Student's ID number
int grade; // Student's grade
};
struct klass{
student studentlist[30];// Array of students/max 30 students
int size; // Size of class
int periodoftheday; // Period of the day the class is in
char nameofclass[5]; // Name of class/max 5 characters
char lastnameofteacher[30]; // Last name of teacher/max 30 characters
};
// Prototypes
void print(student, int);
student createstudent(char, char, int, int, int);
displaystudent(const, student);
addstudenttoclass(student, klass);
void print(student s[], int x)
{
cout << "First name: " << s[x].firstname << endl; // Displays first name
cout << "Last name: " << s[x].lastname << endl; // Displays last name
cout << "Age of student: " << s[x].age << endl; // Displays age
cout << "Student number: " << s[x].studentnumber << endl; // Displays ID number
cout << "Student grade: " << s[x].grade << endl; // Displays grade
cout << endl;
}
int main()
{
student s[1]; // s of type student
int x;
cout << "Enter information of student: " << endl;
for (int x=0; x<1; x++)
{
cout << "Enter first name: " << endl;
cin >> s[x].firstname; // Takes student's first name
cout << "Enter last name: " << endl;
cin >> s[x].lastname; // Takes student's last name
cout << "Enter age: " << endl;
cin >> s[x].age; // Takes student's age
cout << "Enter student number: " << endl;
cin >> s[x].studentnumber; // Takes student's ID number
cout << "Enter grade: " << endl;
cin >> s[x].grade; // Takes student's grade
cout << endl;
}
cout << "Information of student" << endl << endl; // Displays info on student
for (int x=0; x<1; x++)
{print(s, x);
/*
cout << "First name: " << s[x].firstname << endl; // Displays first name
cout << "Last name: " << s[x].lastname << endl; // Displays last name
cout << "Age of student: " << s[x].age << endl; // Displays age
cout << "Student number: " << s[x].studentnumber << endl; // Displays ID number
cout << "Student grade: " << s[x].grade << endl; // Displays grade
cout << endl;
*/
}
system("PAUSE");
return 0;
}
/*
// ***************************************************************************************************************** Incorrect
klass k[1]; // k of type klass
int y;
cout << "Enter information of class: " << endl; // Displays info on class
for (int y=0; y<1; y++)
{
cout >> "Student list: " << endl;
cin >> student studentlist;
cout << "Enter size of class: " << endl;
cin >> k[y].size; // Takes size of class
cout << "Enter period of the day: " << endl;
cin >> k[y].periodoftheday; // Takes period of the day the class is in
cout << "Enter name of class: " << endl;
cin >> k[y].nameofclass[5]; // Takes the name of the class/max 5 characters
cout << "Enter last name of teacher: " << endl;
cin >> k[y].lastnameofteacher[30]; // Takes last name of teacher/max 30 characters
cout << endl;
}
cout << "Information of class" << endl << endl; // Displays info on class
for (int y=0; y<1; y++)
{
cout << student studentlist[30] << endl; // Array of students/max 30 students
cout << "Size of class: " << k[y].size << endl; // Displays size of class
cout << "Period of the day: " << k[y].periodoftheday << endl; // Displays period of the day
cout << "Name of class: " << k[y].nameofclass[5] << endl; // Displays name of class
cout << "Last name of teacher: " << k[y].lastnameofteacher[30]; // Displays last name of teacher
}
student createstudent (char firstname[30], char lastname[30], int age, int studentnumber, int grade); // ??
{
cout << "First name of student: " << endl;
cin >> firstname[30];
cout << "Last name of student: " << endl;
cin >> lastname[30];
cout << "Age of student: " << endl;
cin >> age;
cout << "Student number: " << endl;
cin >> studentnumber;
cout << "Student grade: " << endl;
cin >> grade;
return createstudent; // ??
}
displaystudent (const student& student); // ??
{
student1.print();
}
addstudenttoclass (student1, klass1); // ??
{
// ??
}
struct klass1({}, 30, "ENG3U", "Smith", 1); // ??
student student1=createstudent("Eric", "Cratman", 16, 803612, 10); // ??
addstudenttoclass (student1, klass1); // ??
for (student1:klass1.students); // ??
{
displaystudent(student1);
}
// Part 6
// Part 7
// Part 8
*/
|