Completly stuck on a project

This HW project has me stuck. I can probably write the code but can't figure out how to put it together. If someone could show me a shell that would work I would really appreciate it.

1. Reads in the following data items:
a. Last Name
b. First Name
c. ID #
d. 3 Test Scores
2. Stores data in arrays and sorts the students alphabetically
3. Do not use any global variables, this means that you will pass information between functions using their argument and return value.
4. Calculates average and grade (tests are weighted equally and standard letter grades apply)
5. Displays
a. Student list including all items in 1 above and grade
b. Table showing number of As, Bs, Cs, Ds, and Fs by test
c. Both displays should include header lines
6. Should have functions for 1, 2, 4, 5a, 5b and main
7. Any additional features (such as displaying 5b as a bar chart) get creativity points
8. Use proper indenting, and supply comments (failure to do either can cost up to 10 points each)
9. If the submitted project fails to compile, there will be a 20 point deduction.
Example Output
Last Name First Name Id Test 1 Test 2 Test 3 Grade
Ant Adam 56789 65 72 68 D
Doe Jane 67890 54 64 52 F
Mix Tom 45678 98 83 74 B
Nerd Bobby 12345 95 96 99 A
Sunday Billy 34567 75 65 82 C
Thumb Tom 23456 87 93 77 B

Frequency
Test A B C D F
1 2 1 1 1 1
2 2 1 1 2 0
3 1 1 2 1 1

Put the code you need help with here.


We cant use vectors or global constants. I was going to use a 2D array for grades but couldn't get the function prototype to work without a global constant for size.

Thanks for ANY help.
Hi @musicman74,
are you allowed to
use user-defined types?
classes,structs?
I believe so.
Sorry for the
late answer i was
busy, i would use
an user-defined type
called "Student" to
create an array of
"Students" and
manage the information
by "Group"

-insert info
-print info
-sort students alphabetically
-calculate grades
-etc...

This could be a
first attempt;


Student #1
First Name>>Enrique
Last Name>>Hernandez
Test score #1>>1
Test score #2>>2
Test score #3>>3
Enter ID>>100

Student #2
First Name>>Christopher
Last Name>>Garcia
Test score #1>>8
Test score #2>>9
Test score #3>>10
Enter ID>>101

Student #3
First Name>>Jorge
Last Name>>Rabago
Test score #1>>4
Test score #2>>5
Test score #3>>6
Enter ID>>102


Last Name         First Name        Id         Test 1         Test 2         Test 3         Grade
Hernandez         Enrique           100        1              2              3              X
Garcia            Christopher       101        8              9              10             X
Rabago            Jorge             102        4              5              6              X


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
145
146
147
148
149
150
151
152
153
154
155
156
157
//Students.cpp
//##

#include <iostream>
#include <string>
#include <iomanip>

using namespace std;


class Student{
	public:
		Student();
		static int const TEST_N=3;
		void setFirstName(string FirstName);
		string getFirstName();

		void setLastName(string LastName);
		string getLastName();

		void setTestScore(int Score,int Index);
		int getTestScore(int Index);

		void setID(unsigned int ID);
		unsigned int getID();
		
		void setGrade(char Grade);
		char getGrade();
		
	private:
		string firstName;
		string lastName;
		int test[TEST_N];
		unsigned int id;
		char grade;
};//end class Student

void insert_data(Student group[],int const SIZE);
void print_info(Student group[],int const SIZE);
int dig_num(unsigned int number);

int main(){
	int const STUDENTS=3;
	Student group[STUDENTS];

	insert_data(group,STUDENTS);
	print_info(group,STUDENTS);	
			

return 0; //indicates success
}//end of main

void insert_data(Student group[],int const SIZE){
	for(int i=0;i<SIZE;i++){
		cout<<"\nStudent #"<<i+1<<endl;
		cout<<"First Name>>";
		string fname;
		getline(cin,fname);
		group[i].setFirstName(fname);
		cout<<"Last Name>>";
		string lname;
		getline(cin,lname);
		group[i].setLastName(lname);
		for(int j=0;j<group[i].TEST_N;j++){
			cout<<"Test score #"<<j+1<<">>";
			int ts;
			cin>>ts;
			group[i].setTestScore(ts,j);
		}//end inner for
		cout<<"Enter ID>>";
		unsigned int id;
		cin>>id;
		group[i].setID(id);

		cin.ignore();
					
	}//end outer for
}//end function insert_data

void print_info(Student group[],int const SIZE){
	string ln="Last Name",fn="First Name",id="Id",t1="Test 1",t2="Test 2",t3="Test 3",gd="Grade";
	cout<<"\n\n";
	cout<<ln<<setw(10)<<'\0'<<fn<<setw(10)<<id;
        cout<<setw(10)<<'\0'<<t1<<setw(10)<<'\0'<<t2<<setw(10)<<'\0'<<t3<<setw(10)<<'\0'<<gd<<endl;
	for(int i=0;i<SIZE;i++){
		cout<<group[i].getLastName()<<setw(19-group[i].getLastName().size())<<'\0'<<group[i].getFirstName();
		cout<<setw(9+(fn.size()-group[i].getFirstName().size()))<<'\0'<<group[i].getID();
		for(int j=0;j<group[i].TEST_N;j++){
			if(j==0)
				cout<<setw(12-dig_num(group[i].getID()))<<'\0'<<group[i].getTestScore(j);
			else
				cout<<setw(16-dig_num(group[i].getTestScore(j-1)))<<'\0'<<group[i].getTestScore(j);
		}//end inner for
		cout<<setw(16-dig_num(group[i].getTestScore(2)))<<'\0'<<group[i].getGrade()<<endl;
	}//end outer for
}//end function print_info

int dig_num(unsigned int number){
	int nd=0;
	if(number==0)return 1;
	while(number>0){
		++nd;
		number/=10;
	}//end while
return nd;
}//end function dig_num

Student::Student(){
	setFirstName("");
	setLastName("");
	for(int i=0;i<TEST_N;i++)
		setTestScore(0,i);

	setID(0);
	setGrade('X');
}//end constructor

void Student::setFirstName(string FirstName){
	firstName=FirstName;
}//end method setFirstName

string Student::getFirstName(){
	return firstName;
}//end method getFirstName

void Student::setLastName(string LastName){
	lastName=LastName;
}//end method setLastName

string Student::getLastName(){
	return lastName;
}//end function getLastName

void Student::setTestScore(int Score,int Index){
	test[Index]=Score;
}//end method setTestScore


int Student::getTestScore(int Index){
	return test[Index];
}//end method getTestScore

void Student::setID(unsigned int ID){
	id=ID;
}//end method setID

unsigned int Student::getID(){
	return id;
}//end method getID

void Student::setGrade(char Grade){
	grade=Grade;
}//end method setGrade

char Student::getGrade(){
	return grade;
}//end method getGrade 
Thank you so much. Ill let you know how it works.
@eyenrique
Ended up not using the whole code just parts. It turned out we were supposed to use code that we have not yet covered in class.
Like pointers and sorting algorithms.
Eventually figured it out though. Thanks for the help.
Congratulations!!! @musicman74,
You are welcome!!!,
regards!
hi guys,
i tryed to solve the task too and stuck @ the sorting part:
i thought of two ways of doing it.

1. option:
1
2
3
4
//have for each agument an array         
first_name[SIZE];                                        
last_name[SIZE];                                   
etc....

2.option
1
2
3
4
//have a object array
class student{};
int main()
student student[SIZE];


option.1:
So i only know <algorithm> sort();I think it would work for option.1. So i sort the last_name array alphabetically but dont know how to let the other arrays (first_name, id etc.) switch positions.

so i tryed sorting last_name earlyer with sort:
sort(last_name[0],last_name[SIZE]

and it doesnt worked; stl_iterator_base_types.h opened in the IDE and marked:
typedef typename _Iterator::iterator_category iterator_category;

compiler says:
typedef typename _Iterator::iterator_category iterator_category;


mabye you cant sort arrays, only containers? x_X

option.2:
sort(student.get_last_name[0], student.get_last_name[SIZE]
i dont think you can sort objects this way. :P

so i hope someone can help me out :)
overall there were several solutions found most looked something like this.

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
// *** Sort Data Alphabetically (Last, First)
void SortList(int    aintCnt,                       // # Students  (IN)
              string astrLast[],                    // Last Names  (I/O)
              string astrFirst[],                   // First Names (I/O)
              string astrId[],                      // Student Ids (I/O)
              int    aintTest[][NUMTEST])           // Tests       (I/O)
{   bool   blnChg;                                  // Change Required Flag
    int    intLast;                                 // Last Change Index
    int    intLen;                                  // Number of Items to Check
    int    intTmp = 0;                              // Test Swap Temp
    string strTmp;                                  // String Swap Temp

    intLast = aintCnt;                              // Start with Count
    for (int intPass = 1; intPass < aintCnt && intLast > 0; intPass++)
    {   intLen = intLast - 1;
        intLast = 0;   
        for (int i = 0, intTmp = -1; i < aintCnt - intPass; i++)
        {   blnChg = astrLast[i] > astrLast[i + 1]; // Last Out of Order
            if (astrLast[i] == astrLast[i + 1])     // Last Equal Check First
                blnChg = astrFirst[i] > astrFirst[i + 1];
            if (blnChg)                             // Need to Switch
            {   strTmp = astrLast[i];
                astrLast[i] = astrLast[i + 1];
                astrLast[i + 1] = strTmp;
                strTmp = astrFirst[i];
                astrFirst[i] = astrFirst[i + 1];
                astrFirst[i + 1] = strTmp;
                strTmp = astrId[i];
                astrId[i] = astrId[i + 1];
                astrId[i + 1] = strTmp;
                for (int intTest = 0; intTest < NUMTEST; intTest++)
                {   intTmp = aintTest[i][intTest];
                    aintTest[i][intTest] = aintTest[i + 1][intTest];
                    aintTest[i + 1][intTest] = intTmp;
                }
                intLast = i;
            }
        }
    }
}
[output][/output]
Last edited on
Topic archived. No new replies allowed.