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/
| |
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
| |
Creating a variable "on the heap" basically means that you use dynamic memory resource allotment (the
newand
delete operators).
http://world wide web.cplusplus.com/doc/tutorial/dynamic/
| |
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.
| |
| 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.
| |
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
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.
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