Help for tomorrow's exam - program that can read in exam results

  • Thread starter Thread starter AstroIreland
  • Start date Start date
  • Tags Tags
    Exam Program
Click For Summary

Discussion Overview

The discussion revolves around creating a program in C++ that can read an unknown number of exam results (ranging from 0 to 100) and identify when a number is repeated. Participants explore how to handle dynamic input storage and summation of results until a repeat occurs.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant seeks help with a program that reads exam results and checks for duplicates, expressing uncertainty about how to implement an infinite storage array.
  • Another participant clarifies the requirement to sum all numbers until a second occurrence of the same number is inputted, suggesting this is straightforward with finite resources.
  • There is a discussion about whether to use a fixed-size array or a dynamic approach, with one participant expressing a desire for the program to handle an unknown number of inputs without pre-declaring array size.
  • Some participants suggest using a large sum variable and logical elements instead of storing all inputs, while others emphasize the need for error checking and upper bounds on the sum.
  • There is mention of using floating-point numbers for the sum to accommodate potentially large totals, as well as the possibility of implementing custom data types for large integers.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the best approach to handle dynamic input storage and summation, with differing opinions on whether to save inputs or just track sums and duplicates.

Contextual Notes

Participants express various assumptions about the program's requirements, including the need for error checking and the limitations of memory resources in finite processors.

AstroIreland
Messages
12
Reaction score
0
Hey guys, I am studying astrophys but i have a programming module, so hopefully this is the right place to ask.

I have a few questions that I am having difficulty with so I am going to pose it in the form of a program if that's cool? I can then take it apart to see how its done.
I'd appreciate it if someone has the time!

So, I need a program that can read in exam results that are in putted (the input is in-between 0 to 100) and it is an unknown number of exam results to be inputted.
The program is to look for a repeat number that has been typed in before.

So for example the numbers may be inputted for the next 4000 years until the same two come up.
So how would I go about the program (maybe using arrays?) that can keep accepting inputs to an unknown quantity. When the matching pair of results are found, I would then like all of the user inputted results to be summed and printed to screen.

Any ideas?
Thanks in advance!
 
Physics news on Phys.org
oh, it could be 4000 years or 2 minutes, its the infinite storing array until the match comes up I am having issues with!
 
AstroIreland said:
Hey guys, I am studying astrophys but i have a programming module, so hopefully this is the right place to ask.

I have a few questions that I am having difficulty with so I am going to pose it in the form of a program if that's cool? I can then take it apart to see how its done.
I'd appreciate it if someone has the time!

So, I need a program that can read in exam results that are in putted (the input is in-between 0 to 100) and it is an unknown number of exam results to be inputted.
The program is to look for a repeat number that has been typed in before.

So for example the numbers may be inputted for the next 4000 years until the same two come up.
So how would I go about the program (maybe using arrays?) that can keep accepting inputs to an unknown quantity. When the matching pair of results are found, I would then like all of the user inputted results to be summed and printed to screen.

Any ideas?
Thanks in advance!

Your program requirements are a bit imprecise. Is this close to what you are asking?

** Sum all numbers that are input until you get a 2nd occurrence of the same number input. Numbers are between 0-100.

If so, that's pretty easy to code with finite resources (assuming the sum doesn't grow too large for the size of the summing variable).
 
Thanks for your quick response.
Would I just write a simple array and leave the square parenthesis without a constant?
 
AstroIreland said:
Thanks for your quick response.
Would I just write a simple array and leave the square parenthesis without a constant?

I don't know what you mean by that, but I'm pretty sure the answer is no.

Do you have a particular computer language in mind for this, or is it a thought experiment to help you figure out some other problem. Even if it's a thought experiment, you should be able to write it up in pseudo-code or C.
 
Sorry I didnt specify the language. Yes, it's C++.
It is a question I have devised that would show me how to answer all of my coding questions within the one.
I mean for the initial coding of the array:
eg
int array [];

then the user inputs under cin (continuously until there is a repetition, then sum the numbers.

Know what I mean?
 
AstroIreland said:
Sorry I didnt specify the language. Yes, it's C++.
It is a question I have devised that would show me how to answer all of my coding questions within the one.
I mean for the initial coding of the array:
eg
int array [];

then the user inputs under cin (continuously until there is a repetition, then sum the numbers.

Know what I mean?

I'm understanding a little better, but no guarantees... :smile:

You don't need any large array to write the program the way I described it. You just need one large sum variable, and an array of ______ logical elements...
 
Yeah, see that's what I mean about the specific sum variable.
I want it so the user can vary e.g different schools use the program so the number of results to be in-putted is unknown.
 
If I get what you mean there; it's to put a large number in the array eg
int array [5000];

?

See I would like to be able to have an unknown quantity within the brackets, that does not have to be declared.
 
  • #10
AstroIreland said:
Yeah, see that's what I mean about the specific sum variable.
I want it so the user can vary e.g different schools use the program so the number of results to be in-putted is unknown.

AstroIreland said:
If I get what you mean there; it's to put a large number in the array eg
int array [5000];

?

See I would like to be able to have an unknown quantity within the brackets, that does not have to be declared.

No, do not save the inputs. You only use them to add into an overall sum, and to check to see if they've been input previously.

You can use a large floating-point number for the sum if the number could exceed the capacity of the largest unsigned int variable for the processor you are coding for. Or you could implement your own multi-largest unsigned int variable with your own manual code for doing carrys and so on as the number gets larger. You should always put an upper bound and error checking on any kind of sum like this. A finite processor obviously does not have infinite memory resources.
 
  • #11
berkeman said:
No, do not save the inputs. You only use them to add into an overall sum, and to check to see if they've been input previously.

You can use a large floating-point number for the sum if the number could exceed the capacity of the largest unsigned int variable for the processor you are coding for. Or you could implement your own multi-largest unsigned int variable with your own manual code for doing carrys and so on as the number gets larger. You should always put an upper bound and error checking on any kind of sum like this. A finite processor obviously does not have infinite memory resources.

Thank you for your great reply.
I have had a read over and you have filled in my missing gaps nicely.

I didn't consider large floating points. Cheers!
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
2K
Replies
7
Views
3K
  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 22 ·
Replies
22
Views
6K
Replies
1
Views
2K
Replies
9
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 4 ·
Replies
4
Views
5K
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
6K