***************C PROGRAMMING ONLY*************
Program Specifications:
1. Create a struct with at least 3 fields - any struct you want but explain it in your comments in the code. Populate at least 10 elements in an array of elements of this struct type with a limit of 1000 elements.
2. Create an array on the heap to store the same number of populated elements from the stack array.
3. Copy the values from the stack array into the dynamic array.
The program will output the contents from each array, one at a time.
** You can have a menu system if you wish but it is not a requirement **
4. Finally, create a BIN file to store the contents of the array on the heap.
// C program to create array of structures on Stack and Heap
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
// struct representing a student
typedef struct
{
int id; // id of student
int score; // score of student
char grade; // grade of student
}student;
int main(void) {
srand(time(NULL));
const int MAXSIZE = 1000;
student students_stack[MAXSIZE];
int numElements = 10;
int i;
// loop to populate 10 elements in array in stack
for(i=0;i<numElements;i++)
{
students_stack[i].id = i+1;
students_stack[i].score = rand()%101;
if(students_stack[i].score >=90)
students_stack[i].grade = 'A';
else if(students_stack[i].score >=80)
students_stack[i].grade = 'B';
else if(students_stack[i].score >=70)
students_stack[i].grade = 'C';
else if(students_stack[i].score >=50)
students_stack[i].grade = 'D';
else
students_stack[i].grade = 'F';
}
// Create an array on the heap to store the same number of populated elements from the stack array.
student *students_heap = (student*)malloc(numElements*sizeof(student));
// if memory not allocated, exit
if(students_heap == NULL)
{
printf("\n Memory not allocated");
return EXIT_FAILURE;
}
//Copy the values from the stack array into the dynamic array.
for(i=0;i<numElements;i++)
{
students_heap[i].id = students_stack[i].id;
students_heap[i].score = students_stack[i].score;
students_heap[i].grade = students_stack[i].grade;
}
// print the elements from both the array
for(i=0;i<numElements;i++)
{
printf("\n Stack : ");
printf(" ID : %d Score : %d Grade : %c",students_stack[i].id,students_stack[i].score,students_stack[i].grade);
printf("\n Heap : ");
printf(" ID : %d Score : %d Grade : %c",students_heap[i].id,students_heap[i].score,students_heap[i].grade);
}
// write contents of heap to binary file
FILE *filePtr = fopen("students.bin","w");
if(filePtr == NULL)
{
printf("Unable to open file");
return EXIT_FAILURE;
}
for(i=0;i<numElements;i++)
{
if(i != numElements-1)
fprintf(filePtr,"%d %d %c\n",students_heap[i].id,students_heap[i].score,students_heap[i].grade);
else
fprintf(filePtr,"%d %d %c",students_heap[i].id,students_heap[i].score,students_heap[i].grade);
}
fclose(filePtr);
return EXIT_SUCCESS;
}
//end of program
Output:

***************C PROGRAMMING ONLY************* Demonstrate the ability to create an array on the stack Demonstrate the ability...
* C PROGRAMMING* Outcomes: Demonstrate the ability to create and use linked lists in dynamic memory Demonstrate the ability to add nodes and remove nodes from a linked list of structs Program Specifications: Write a program that creates the following struct (you can give it whatever name you want): char name[100]; int age; float weight; Create the following menu system: Add a Record Display All Records Quit When the user selects (1) you will prompt them for a name, age,...
Java Programing Code only Ragged Array Assignment Outcome: Student will demonstrate the ability to create and use a 2D array Student will demonstrate the ability to create and use a jagged array Student will demonstrate the ability to design a menu system Student will demonstrate the ability to think Program Specifications: Write a program that does the following: Uses a menu system Creates an array with less than 25 rows and greater than 5 rows and an unknown number of...
The following needs to be in C programming ! Outcomes: Demonstrate the ability to design a menu driven program. Demonstrate the ability to reuse previous code to create a new assignment. Demonstrate the ability to use appropriate program logic. Program Specifications: DESIGN and IMPLEMENT a menu driven program that uses the following menu and can perform all menu items: Enter a payroll record for one person Display all paycheck stubs Display total gross payroll from all pay records. Quit program...
C++ Create an array-based implementation of a stack. Each element of the stack should store a string. The stack class should include 3 private member variables (maximum stack size, top of the stack index, and a pointer to the array that holds the stack elements). Public member methods should include a constructor (with an argument of stack maximum size that is used to create a dynamic array), a destructor (that deletes the dynamic array), a push method (argument is a...
Create an array-based implementation of a stack. Each element of the stack should store a string. The stack class should include 3 private member variables (maximum stack size, top of the stack index, and a pointer to the array that holds the stack elements). Public member methods should include a constructor (with an argument of stack maximum size that is used to create a dynamic array), a destructor (that deletes the dynamic array), a push method (argument is a string),...
Question: C Programming Problem: Pointer and Struct Description: The purpose of this assignment is to prov... C Programming Problem: Pointer and Struct Description: The purpose of this assignment is to provide practice programming using structs and pointers. Your program will accept user input and store it in a dynamic array of structs. First, you will define a structure to describe a item to be bought. Your program will prompt the user for the initial size of the array. It will...
*MUST BE IN C PROGRAMMING* Demonstrate the ability to think critically Demonstrate the ability to work with strings and chars Demonstrate the ability to design a menu system Write a simple program that allows the user to enter a number between 1 and 1000. The program will then display the Roman numeral equivalent. Allow the user to keep entering numbers for conversion to Roman numerals, or to quit, using a menu system of your own design. Submission Requirements: You are to write...
Language: C Programming, Please leave as many comments as possible! Create a program that has a menu as shown: 1. Generate 500 Random Numbers between 1 and 500 2. Show Current Set of Random Numbers ordered from Low To High 3. Show Frequency of each number from 1 to 500 4. Quit The program will store all random number in an array on the heap.
Methods and File Output and Exceptions Outcome: Student will demonstrate the ability to write, use and call methods Student will demonstrate the ability to pass values to and from methods Student will demonstrate the ability to catch exceptions Student will demonstrate the ability to create a text file Student will demonstrate the ability to validate input data Program Specifications: You to write a menu driven program. The program will use a switch statement. The cases will be as follows: Get...
I need to implement raw array Stack for create empty stack, isEmpty, isFull, push, pop, and size using below pseudo code. I need two classes with stack pseudo code implementation and the main method to demonstrate the correct working of each operation. pseudo code StackADT (using raw array) class StackADT { int top int items[] int max StackADT(int n) Initialize array to n capacity top = 0 max = n boolean isEmpty() if array has no elements return true else...