Write a Program That Reads Students' Quizzes Scores From a User Populated Dynamic Array

I'm a beginner in C++ and I already feel lost. My instructor assigned us this trouble:

Create a Static 2D Assortment on the Stack to hold a set up of four exam scores for five students.

Optional:
Create a Dynamic Assortment (on the heap) to agree a fix of four test scores for five students. (Hint: you must write your ain access algorithm).

Create dynamic parallel arrays (on the heap) to agree student names, student id, average score, and a letter grade based on standard grade scale.

Populate the arrays from the file Student Data.txt

Write a program to do the following tasks:

1. Calculate boilerplate score for each educatee.
2. Assign letter grade for each student.
3. Display name, id, scores, average, and grade for each student.
4. calculate the form average score and display.

If anyone could merely assist me get started, I would profoundly appreciate it.

Terminal edited on

Try information technology out yourself. If you face whatsoever specific problem, then inquire here.

If yous are totally lost, and so y'all should accept help from your professor or fellow-mates.

Creating a variable "on the stack" basically means that it's a local variable in a function ("automatic retention allocation").
http://www.cplusplus.com/forum/beginner/18101/

                        ane
2
3
4
5
                                                  void                          func() {                          int                          a;                          // on the Stack                          auto                          int                          b;                          // same as above, the keyword "auto" is useless                          }                      

Global (and static) variables practice not live on the stack. They are allocated statically.
http://en.wikipedia.org/wiki/Static_memory_allocation
http://en.wikipedia.org/wiki/Static_variable

                        ane
2
3
4
5
half dozen
                                                  int                          a;                          // not on the Stack or Heap                          void                          func() {                          static                          int                          b;                          // not on the Stack or Heap                          }                      

Creating a variable "on the heap" basically means that you use dynamic memory resource allotment (the

new

and

delete

operators).
http://world wide web.cplusplus.com/doc/tutorial/dynamic/

                        1
2
3
4
5
vi
7
8
                                                  void                          func() {                          int                          *a =                          new                          int[100];                          // dynamically allocate 100 int's on the Heap                          // ... use them...                          delete[] a;                          // free the memory once no longer needed                          }                      

Dynamic memory resource allotment is used considering the Heap is much larger than the Stack. So if y'all demand to allocate big amounts of memory, it's a bad thought to allocate them on the Stack.
http://en.wikipedia.org/wiki/Stack_overflow

With that out of the way...

Undefined95 wrote:
Create a Static 2D Array on the Stack to hold a gear up of 4 test scores for five students.

int scores[5][four];

Undefined95 wrote:
Create dynamic parallel arrays (on the heap) to concur student names, pupil id, average score, and a letter grade based on standard grade scale.

Populate the arrays from the file Student Data.txt

Did y'all learn about

struct

's? Are you allowed to utilize

struct

'southward in your homework? They would simplify things a lot.

                        one
ii
3
iv
5
6
7
8
9
10
11
12
xiii
14
15
16
17
                                                  #include <string>                          struct                          Student {     std::string name;     std::string id;                          float                          average_score;     std::string letter_grade;                          // not char, in order to allow for things like "A+" maybe                          };                          // ...                          Student *ps =                          new                          Student[x];                          // where x is how many students y'all read data about                          // ...                          delete[] ps;                      
Undefined95 wrote:
If anyone could just assistance me get started, I would profoundly appreciate it.

You may desire to read through the tutorial on this site.
http://world wide web.cplusplus.com/doc/tutorial/

I take not however learned about struct's. Is there a different way to go near the problem?

All the more reason to get assist from your teacher or classmates. Nosotros have a policy not to do homework for people. We will help you if you post lawmaking to evidence what you have done so far and explicate what you are stuck on, merely we won't do the piece of work for you. U.s.a. doing it won't do good yous at all and will just brand yous dependent on us or others to go on to practice the work, especially if you don't take the fourth dimension to understand the lawmaking.

you just know the basics?i mean just arrays?

I do not want anyone to do my homework for me. All I wanted was some input/advice on how to get about the problem. I do know the basics/arrays.

Thats a good attitude to have, simply getting someone to do information technology for y'all would be of no benefit. Anyway, catfish666 has given a overnice explanation but aslope his/her post I have added some code below.

Its worth checking if yous get more than marks when using dynamically allocated arrays... more marks is always practiced :)

Notwithstanding, the example below is statically allocated.

                        i
2
3
iv
five
6
7
8
9
10
11
12
13
xiv
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
                                                  #include <iostream>                          int                          main() {                          // array of 5 downwards (students) by 4 beyond (scores) - remember arrays start at 0                          int                          scores[5][4];                          /* 	 		So scores volition wait similar this..  				[0][0-three]  1st Pupil, 4 exam scores 				[1][0-3]  2nd Pupil, 4 test scores 				[two][0-iii]  3rd Student, 4 test scores 				[3][0-3]  4th Student, 4 test scores 				[iv][0-3]  5th Student, 4 test scores  		So if I wanted to access student three and the 2nd score 		for that student i would use index [2][1] as arrays  		get-go at 0 not 1  		so reading information technology:  		studentScore = scores[2][1];   		or writing to it:  		scores[2][1] = four; 	 	*/                          return                          0; }                                              

Using For loops yous could go through each student 1 by ane getting their iv scores quite hands. The post-obit links may exist helpful to y'all:

Arrays: http://www.cplusplus.com/doc/tutorial/arrays/
Flow Control: http://www.cplusplus.com/doc/tutorial/control/

Cheers and at this point I'grand going for the static 2nd array instead of the dynamic array since I don't quite understand those yet.

Undefined95 wrote:
Thank you and at this bespeak I'g going for the static 2D array instead of the dynamic array since I don't quite sympathize those yet.

Dynamic arrays are allocated on the heap.
In C++ you utilize the

operator new[]

to allocate them, and

operator delete[]

to deallocate them.

When you employ

new[]

, it allocates an array in retentivity and returns the memory address of the start chemical element. You need to "salvage" the retention address, and yous do so by putting it in a pointer (a arrow being a variable that stores a memory address).

You must go on the memory address, considering later on you lot'll need to feed it to

delete[]

in order to deallocate the dynamic array.

This is valid in C and C++. Newer languages (C#, Java, D) don't require y'all to release the memory manually, because they take a garbage collector. The purpose of a GC is exactly that: to automatically release unused resources.

Oh okay. Thanks for explaining that. My problem now is just getting the data from my file to exist read into the different arrays I am trying to create.

Topic archived. No new replies allowed.

bischofmazenvide.blogspot.com

Source: http://www.cplusplus.com/forum/beginner/138778/

0 Response to "Write a Program That Reads Students' Quizzes Scores From a User Populated Dynamic Array"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel