C programming.
1.Create a program that does the following
- Creates three pointers, a character pointer professor, and two
integer pointers student_ids, grades
- Using dynamic memory, use calloc to allocate 256 characters for
the professor pointer
- Prompts the professor for their name, and the number of students
to mark.
- Stores the professor’s name using the professor pointer and in an
integer the number of students to mark.
- Using dynamic memory, use malloc to allocate memory for
student_ids and grades to hold the number of students the professor
needs to mark.
- The program does not need to do anything else, ensure that you
free your memory before terminating.
- You will need to review the malloc, calloc, and sizeof
documentation.
2. Building upon the previous questions you will create a
marking system for professors at UOIT.
- Structs can be used the same as any other data type in C, instead
of having two arrays for the grades and student ids create a struct
called grade that contains two integers: student_id and mark.
- Create a function grade_students which takes the following
arguments: a pointer to the grade struct called grades, and an
integer num_students. The function returns void and does the
following:
- Opens the file grades.txt in write mode
- Using the num_students parameter iterates through all of the
grade structs pointed to by the grades parameter (remember arrays
are pointers, you can treat pointers like arrays).
- For each grade structure adds the mark member of the struct to a
variable called sum that holds the sum of all student’s
grades.
- For each grade structure write to the file grades.txt the student
id and the mark on a single line.
PLEASE REFER BELOW CODE
#include<stdlib.h>
#include<stdio.h>
typedef struct grade
{
int student_id;
int mark;
}grade;
void grade_students(struct grade *grades, int
num_students)
{
FILE *fptr;
int i,sum;
fptr = fopen("grades.txt", "w");
sum = 0;
for(i = 0; i < num_students; i++)
{
sum +=
grades[i].mark;
fprintf(fptr,
"%d\t%d\n", grades[i].student_id,grades[i].mark);
}
fclose(fptr);
}
int main()
{
int num_students;
struct grade *g;
char *professor;
int *student_ids;
int *grades;
int i;
professor = (char*)calloc(256,
sizeof(char));
printf("Enter Professor name : ");
scanf("%[^\n]", professor);
printf("Enter number of students to mark :
");
scanf("%d", &num_students);
// creating two arrays using malloc
student_ids = (int*)malloc(sizeof(int) *
num_students);
grades = (int*)malloc(sizeof(int) *
num_students);
//b) //allocating array of struct for num of
students
g = (grade*)malloc(sizeof(grade) *
num_students);
//asking user input
for(i = 0; i < num_students; i++)
{
printf("Enter id and
marks of %d student : ", (i+1));
scanf("%d %d",
&g[i].student_id,&g[i].mark);
}
grade_students(g, num_students); //calling
function
return 0;
}
PLEASE REFER BELOW OUTPUT

OUTPUT FILE grades.txt is
1 45
2 48
3 90
4 99
C programming. 1.Create a program that does the following - Creates three pointers, a character pointer...
I have some questions about pointers/pointer arithmetic in C++ 1) Pointers and Pointer Arithmetic a.) What is the difference between statically allocated arrays and dynamically allocated arrays (be brief) b.) Which of the following pointers can be used for a dynamically allocated array? (Circle) char ptr; char * ptr; char ptr *; char ptr[]; char [] ptr; c.) Show now, using that pointer, how to dynamically allocate array of characters of size 10: (don't use malloc) d.) Which of the...
IN C PROGRAMMING, NOT C++ Rewrite the program you submitted for A8 to use pointers, pointer notation and arithmetic, etc. as follows: If you did not complete A8, you will need to start with those instructions, and then, change your code based on the instructions here The main() function should: Create a fixed or dynamic array, e.g., double grade[SIZE] or double *grade = malloc(...) or calloc(...) Concerning the function call for getData(), pass the address of the array and its...
Rewrite the program you submitted for A8 to use pointers, pointer notation and arithmetic, etc. as follows: If you did not complete A8, you will need to start with those instructions, and then, change your code based on the instructions here The main() function should: Create a fixed or dynamic array, e.g., double grade[SIZE] or double *grade = malloc(...) or calloc(...) Concerning the function call for getData(), pass the address of the array and its size to pointers; depending on...
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...
Using C, create a data file with the first number being an integer. The value of that integer will be the number of further integers which follow it in the file. Write the code to read the first number into the integer variable how_many.Please help me with the file :((This comes from this question:Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory allocation) and have it pointed to by a pointer (of type int...
C programming The program will require the following structure: struct _data { char *name; long number; }; The program will require command line arguments: int main(int argv, char **argc) { Where argv is the number of arguments and argc is an array holding the arguments (each is a string). Your program must catch any case where no command line arguement was provided and print a warning message (see below). You MUST include/use the following functions, defined as follows: int SCAN(FILE...
C++ Project - Create a memory game in c++ using structs and pointers. For this exercise, you will create a simple version of the Memory Game. You will again be working with multiple functions and arrays. You will be using pointers for your arrays and you must use a struct to store the move and pass it to functions as needed. Program Design You may want to create two different 4x4 arrays. One to store the symbols the player is...
IN C ONLY As mentioned earlier there are two changes we are going to make from lab 5, The file you read into data structures can be any length. studentInfo array will be stored in another struct called studentList that will contain the Student pointer and current length of the list. Sometimes data can be used in structs that correlate between variables so it's convenient to store the data in the same struct. Instead of tracking a length variable all...
Modify the following C code to the changes listed below. Please format code correctly. #include <stdio.h> #include <stdlib.h> #define SIZE 5 void displayData(int [], int s); void getData(int array[], int size) { for(int i=0; i<SIZE; i++) { scanf("%d", &array[i]); } } int main() { int grades[SIZE]; for(int i=0; i<SIZE; i++) { grades[i] = 0; } getData(grades,SIZE); displayData(grades, SIZE); } void displayData(int grades[], int size) { for(int i=0; i<size;...
In C++ Assignment 8 - Test Scores Be sure to read through Chapter 10 before starting this assignment. Your job is to write a program to process test scores for a class. Input Data You will input a test grade (integer value) for each student in a class. Validation Tests are graded on a 100 point scale with a 5 point bonus question. So a valid grade should be 0 through 105, inclusive. Processing Your program should work for any...