C++ :: Project Combining Arrays / Pointers And Structures
May 6, 2014
Write a program that uses a record structure to store a Student Name, Student ID, Test Scores, Average Test Score, and Grade. The program should keep a list of test scores for a group of 6 students. The program should ask for the name, ID, and four test scores for each student. Then the average test score should be calculated and stored. The course grade should be based on the following scale:
Average Test Score Course Grade
------------------ ------------
90 - 100 A
80 - 89 B
70 - 79 C
60 - 69 D
59 or below F
A table should be displayed on the screen listing each student's name, ID, average test score, and course grade. Implement with functions.
My code runs but it isnt returning anything (readable/correct) and i have no clue why. This is what i have so far:
#include <iostream>
using namespace std;
const int columns = 4;
struct StuRec //user defined datatype {
int id[6];
char names[6][20];
[Code] .....
it compiles completely but at the end instead of showing the student name ID average score and class grade it shows.... [URL] .....
View 2 Replies
ADVERTISEMENT
May 5, 2014
Write a program that uses a record structure to store a Student Name, Student ID, Test Scores, Average Test Score, and Grade. The program should keep a list of test scores for a group of 6 students. The program should ask for the name, ID, and four test scores for each student. Then the average test score should be calculated and stored. The course grade should be based on the following scale:
Average Test Score Course Grade
------------------ ------------
90 - 100 A
80 - 89 B
70 - 79 C
60 - 69 D
59 or below F
A table should be displayed on the screen listing each student's name, ID, average test score, and course grade. Implement with functions.
My code runs but it isnt returning anything(readable/correct) and i have no clue why. This is what i have so far:
#include <iostream>
using namespace std;
const int columns = 4;
struct StuRec //user defined datatype {
int id[6];
char names[6][20];
int scores[6][4];
double avg[6];
char grade[6];
}; //semi-colon required
[Code] ...
View 8 Replies
View Related
Apr 5, 2013
I have to do a project for Programming and he said in quotes
"Programming exercise 10.6: the programming project is as described, except do not represent the points using structures.
Assume, as known, the ten (x,y)-values corresponding to x=0.0, 0.1, 0.3, 0.45 ..etc and use y-values from the
function xsin(x); as in (x,y)=(x, xsin(x)) = (0.3, 0.3sin(0.3)).
Use value n+1=10, so the LaGrange polynomial will be order = 9."
What does it mean to not represent the points using structures??
View 2 Replies
View Related
Apr 15, 2013
I'm trying to write a function that takes a 32bit address and a data to store at this address.
I'm wanting to take the 32 bit memory address eg 0x12345678 and split it
into 4 x 2 bytes
12, 34, 56, 78
then each of the 4 entries is at most a 256 entry array.eg
FF, FF, FF, FF
So in this example, 0x12 points to 0x34 in the second array, which points to 0x56 in the third array, which finally points to 0x78 in the last array. This last array holds the actual data.
After successfully doing 0x12345678, say I might get a read for 0x1234AABB. So, the first and second pointers already exist, but I then have to create and write to dynamically created arrays.
The arrays need to have all entries set to NULL so that i know whether to follow the pointers to overwrite a previously entered value or create new arrays and pointers.
It all looks good and simple in the pseudo code I've written up but I'm having trouble coding it. I'm currently trying to deal with the first entry case, ie all array elements are NULL, but I'm getting confused with the pointers and creation of new arrays.
void cpu::store(unsigned int mem_add,unsigned int mem_val) {
int first = (mem_address&4278190080)>>24;
int second = (mem_address&16711680)>>16;
int third = (mem_address&65280)>>8;
int fourth= (mem_address&255);
[Code] .....
A1 has been declared as
int* A1[256] ;
View 3 Replies
View Related
Aug 9, 2013
How do I store pointers to a struct in an array ? I am using sprintf to concatenate some values together and then output it to an array in its 1st argument. A portion of my code is shown below.
Code:
int count = 0;
struct addx {
int a;
[Code].....
View 1 Replies
View Related
Mar 24, 2015
concepts on pointers to structures and referencing for the following two lines.
//address of the variable "struct UIP_IP_BUF" is assigned as srcipaddr
uip_ds6_nbr_add(&UIP_IP_BUF->srcipaddr,
//data type "uip_lladdr_t" pointer points to the address of array an "nd6_opt_llao" with size UIP_ND6_OPT_DATA_OFFSET
(uip_lladdr_t *)&nd6_opt_llao[UIP_ND6_OPT_DATA_OFFSET]
View 5 Replies
View Related
Feb 13, 2013
This is my program and i dont know what is the better strategy to display the output perfectly align with the title, when i input a long variable or short the variable move and it does not align with its title. what can i do.
#include <iostream>
#include <string>
#include <string.h>
#include <cstdlib>
#include <cstring>
#include <iomanip>
using namespace std;
struct book {
[Code] ....
View 1 Replies
View Related
Feb 24, 2013
Background: I'm writing a convolutional encoder (and decoder, eventually) for a microprocessor (PIC24), for which I'm using structs and pointers to move from state to state. So far as I'm aware, everything I'm using in the PIC involves nothing other than ANSI C.
I have a little experience with structures, having written a linked-list program for a class a couple years back, but nothing since and never used structure arrays. I have the feeling I'm missing something basic here, which is what's so frustrating. The most confusing error (and I suspect the root of most of them) is the 'state undeclared', which I just can't figure.
The errors I'm getting are:
encoder.c:11: warning: 'struct memstate' declared inside parameter list
encoder.c:11: warning: its scope is only this definition or declaration, which is probably not what you want
encoder.c: In function 'state_init':
encoder.c:22: error: two or more data types in declaration specifiers
encoder.c:25: error: 'state' undeclared (first use in this function)
encoder.c:25: error: (Each undeclared identifier is reported only once
[Code]....
Code:
Code: //Includes
#include <stdlib.h>
//------------------------------------------------------------------------------
//Creates state machine and passes back pointer to 00 state
void state_init(struct memstate* startpoint)
{
extern struct memstate
{
char output0; //output if next input is 0
[code]...
NB: I'm aware that at the moment, this code will do nothing except spin round that do-while loop. Once it's actually compiling I'll drop in some simple button-based test code so it'll check for the correct output.
View 9 Replies
View Related
Sep 26, 2014
typedef struct example_dt_struct {
int a;
float b;
char* c;
};
typedef void(*func)(example_dt_struct *s, int e, int f);
void f(func *n){}
how can i use example_dt_structure with my function pointer into f()
View 5 Replies
View Related
Mar 26, 2013
I wanted to sort two structure-arrays according to their element values and get their indices changed accordingly.For example if my array is
A[]= { 2 4 1 8 6}
indices[]={ 1 2 3 4 5}
then after sorting it should become
A[]= { 1 2 4 6 8}
indices[]={ 3 1 2 5 4}
I tried implementing it using the following code but I failed to get correct output.
Code:
#include<iostream>
#include<cstdio>
using namespace std;
#define inf 100000
struct array
{
int x;
int y;
};
[code]....
View 4 Replies
View Related
Mar 1, 2014
# include <conio.h>
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
[Code]....
I tired changing the conditions in the for loops, but then I end up entering information multiple times and I want that to be the user's option. Do I have to change the for loops or something else? I've tried everything to get what I want but nothing works. When I print the receipt, only the last food Item that I entered prints.
View 14 Replies
View Related
Feb 7, 2012
We are supposed to create a menu with an option to add a car (make, model etc) to inventory. I have the structure format set up as far as adding the car, but I am stuck on how to make it a dynamic array of structures or whatnot (I'm not really sure on what I'm trying to do in the first place!) Basically, the user can choose to add a car and its info in. How do you set up the array to add whatever number of cars is needed? Will it be able to add more cars should the user come back to the program later?
This is the instruction of this portion of the project :
Menu Application
Add a car to inventory
Prompted to add
Make, Model and Year, Color, Miles, Price
Finish (adds the car to the file)
Cancel takes you to the main menu
View 1 Replies
View Related
Dec 15, 2014
My problem is when I try to show the contents of my text files after I add a contact it wont show me anything.
#include <iostream>
#include <conio.h>
#include <string>
#include <windows.h>
#include <fstream>
#include <cstdlib>
using namespace std;
//prototypes
void printline(char, int);
[code].....
View 3 Replies
View Related
Dec 24, 2013
So when if you want to change the values themselves for example in an array (just for example) this is valid;
void test(int* test)
{
test[0] += 10;
}
int bob[] {1, 3, 5};
If you did that bob[0] would not equal 11. All well and good right?
Now if you do this?
int sally = 33;
test(sallay);
This wouldn't work at all you actually have to use
void test(int& test)
{
test += 10;
}
how the memory addresses etc. are working here? I don't understand why you need to use & the reference operator if it's not an array? Why wouldn't that still work?
View 3 Replies
View Related
Apr 14, 2013
Here is my program to look up words. How do I use character pointers instead of using arrays?
Code:
#include <stdio.h>
struct entry
{
[Code].....
View 2 Replies
View Related
Feb 11, 2013
I am having troubles with dynamic arrays and pointers. All the errors are of that kind. I think when I am assigning malloc to an array we assign to its address.
Code:
/*Create an array of genes of the large matrix*/
gene_t gene,gene1,gene2;
gene=malloc(INITIAL*sizeof(gene2)); Code:
while(...) {
if (gene_num==current_size){
[Code] .....
View 9 Replies
View Related
Jun 27, 2013
Set an Array (a[10]) and a Pointer to that array (*pa) and code a loop (for( ; ; loop) that will advance that pointer (*pa) and will set a new content into it with each loop. that means that in the end of the day, my program will automatically set content to each cell of the array by promoting the pointer by 1 and add the sum to that pointer.
When I run the program it prints the address of the cells instead the value of it.
Code:
#include <stdio.h>
void main() {
float a[11], *pa; // Array and ptr set.
int i; // counter for the loop.
pa = a;
for (i=0 ; i<=10 ; i++) // the loop itself.
[Code] .....
View 3 Replies
View Related
Jul 17, 2013
Merging two arrays together using pointers!
View 4 Replies
View Related
Aug 30, 2013
I came across the below code snippet in a project and was not sure how value of variable "response" is computed. Here as we can see, pic_data holds two one dimensional arrays but "response" access both the single dimensional array as two dimensional array.
Code:
#define MAX 100
#define MAXBUF 100
u32 response;
u32 index;
}
[code]....
View 3 Replies
View Related
Feb 6, 2013
I have a problem with a pointer and a bidimensional array. Here's the code:
typedef char t_board[5][4];
int i,j;
t_board *copy (t_board b) {
t_board *ptr;
ptr = (t_board *) malloc (sizeof(t_board));
[Code] ...
After this, I print new_board, and its ok; but the following code after the call to copy, crashes. Don't know why. if I remove the statement new_board = copy(some_board); , the code that follows runs ok.
View 4 Replies
View Related
Aug 3, 2014
I'm writing quite a large program that needs to work with very large arrays (up to 100 million integers). It is necessary that i can access every point of the array directly (without running through the array) and that I use as little memory as possible. I first wrote the program with pointers that point to allocated heap memory. It works fine but now I wanted to use smart pointers instead (so I'm sure to have no memory leaks). Here's a simple visualization of my problem:
#include <iostream>
#include <memory>
using namespace std;
unique_ptr<int[]> upArray;
int main() {
int nArrayLength = 10;
[Code] ....
There are 2 things that do not work how I would like the to:
1. It wants me to assign the heap memory in one step: unique_ptr<int[]> upArray(new int[nArrayLength]); But I'd like to have the unique_ptr in my Class_Declaration before I know the array length and allocate the memory later.
2. *(upArray + i) = i;
cout << *(upArray + i);
Those lines don't work! How else can I do it.
View 6 Replies
View Related
Feb 25, 2015
I am trying to use pointers to arrays in my function.
I can get the pointers to work outside of a function but I just can't figure out how to make them work in my function.jwhittle58, on 25 February 2015 - 06:06 PM, said:
I am trying to use pointers to arrays in my function. I can get the pointers to work outside of a function but I just can't figure out how to make them work in my function.
View 8 Replies
View Related
May 7, 2013
I am looking for an example of when passing arrays to other data that has pointers,
I understand the terms I would just like to see a small example of code that actually demonstrates this process.
View 4 Replies
View Related
Jan 17, 2014
the book I learn from gave a task to write a program which gets a matrix , and we have to write a function that switches 2 columns or rows the user inputs .as far as I know a function can not change variables in the main function without using pointers .so , theoretically, can a function described here can be written without using pointers ? as far as I tried - it can not.
View 9 Replies
View Related
Apr 25, 2014
Class with Pointers and Dynamic Arrays
View 2 Replies
View Related
Feb 11, 2013
Code:
typedef struct {
name_t name;
float beta[beta_num];
} gene_t;
[Code] ....
Is gene an array of address ? How come the compare function doesn't work ?
View 1 Replies
View Related