Please complete the c++ code. The code that needs completing is outlined in the comments.
#include <stdio.h>
#include<stdlib.h>
#include<math.h>
struct student{
int id; int score;};
struct student* allocate(){
/*Allocate memory for ten students*/
/*return the pointer*/
}
void generate(struct student* students){
/*Generate random and unique ID and scores for ten students, ID being between 1 and 10, scores between 0 and 100*/
}
void output(struct student* students){
/*Output information about the ten students in the format: ID1 Score1 ID2 score2 ID3 score3 ... ID10 score10*/
}
void summary(struct student* students){
/*Compute and print the minimum, maximum and average scores of the ten students*/
}
void deallocate(struct student* stud){
/*Deallocate memory from stud*/
}
int main(){
struct student* stud = NULL;
/*call allocate*/
/*call generate*/
/*call output*/
/*call summary*/
/*call deallocate*/
return 0;
}
// C code
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <assert.h>
struct student
{
int id;
int score;
};
struct student* allocate()
{
/*Allocate memory for ten students*/
struct student* s = malloc(10 * sizeof(struct
student));
/*return the pointer*/
return s;
}
void generate(struct student* students)
{
/*Generate random and unique ID and scores for ten
students, ID being between 1 and 10, scores between 0 and
100*/
int i, j;
int new;// To check for new initials
for (i = 0; i < 10; i++)
{
new = 1;
students[i].id = ((rand() % 10) +
1);
for (j = 0; j < i; j++)
{
if (students[i].id
== students[j].id)
{
new = 0;
break;
}
}
if(new == 0)
{
i--;
continue;
}
students[i].score = ((rand() % 100));
}
}
void output(struct student* students)
{
/*Output information about the ten students in the
format: ID1 Score1 ID2 score2 ID3 score3 ... ID10 score10*/
int i;
for (i = 0;i < 10; i++)
{
printf("ID: %d ",
students[i].id);
printf("Score: %d\n",
students[i].score);
}
}
void summary(struct student* students)
{
/*Compute and print the minimum, maximum and average
scores of the ten students*/
int i, min, max;
float avg, sum = 0;
min = students[0].score;
max = students[0].score;
for (i = 0; i<10; i++)
{
if (students[i].score <
min)
{
min =
students[i].score;
}
if (students[i].score >
max)
{
max =
students[i].score;
}
sum = sum +
students[i].score;
}
avg = (sum / 10);
printf("Minimum score: %d\n", min);
printf("Maximum score: %d\n", max);
printf("Average score: %g\n", avg);
}
void deallocate(struct student* s)
{
/*Deallocate memory from stud*/
assert(s != NULL); // Break off program if null, so we
don't get a segmentation fault in freeing the memory.
free(s);
}
int main()
{
srand(time(NULL));
struct student* stud = NULL;
/*call allocate*/
stud = allocate();
/*call generate*/
generate(stud);
/*call output*/
output(stud);
/*call summary*/
summary(stud);
/*call deallocate*/
deallocate(stud);
return 0;
}
/*
output:
ID: 1 Score: 35
ID: 8 Score: 71
ID: 2 Score: 33
ID: 7 Score: 49
ID: 4 Score: 88
ID: 3 Score: 6
ID: 6 Score: 19
ID: 10 Score: 48
ID: 9 Score: 5
ID: 5 Score: 15
Minimum score: 5
Maximum score: 88
Average score: 36.9
*/
Please complete the c++ code. The code that needs completing is outlined in the comments. #include...
C ++ 1. Write down the missing code according to the comments. #include <cstdlib> #include <iostream> using namespace std; void fun1(int radius) { /* dynamic memory management */ double * dmptr; double circumference; /* add the code below to: - allocate a memory location for a double and nameless variable in heap and assign its address to the pointer - assign 3.14 to the variable in heap via the pointer....
I am trying to write C programming code and output will be as
below
but I donno how to get the result analysis part.
help me to add the 2nd part with my code:
here is my code below:
#include <stdio.h>
#define MAX 100
struct studentMarkVariable{
int id;
float marks;
};
void getData(struct studentMarkVariable arrs[]);
void show(struct studentMarkVariable arrs[]);
int main()
{
printf ("####### Marks Analyzer V3.0 ####### \n");
struct studentMarkVariable
arrs[MAX];
getData(arrs);
show(arrs);
return 0;
}...
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...
ASSIGNMENT DUE DATE GOT PUSHED BACK TO LATE THIS WEEK. PLEASE READ COMMENTS AND CODE BEFORE ANSWERING CODING SECTIONS HW07 #Q1-Q5 HW08 #Q1-Q2 // READ BEFORE YOU START: // Please read the given Word document for the project description with an illustrartive diagram. // You are given a partially completed program that creates a list of students for a school. // Each student has the corresponding information: name, standard, and a linked list of absents. // Please read the instructions...
QUESTION 6 What is the output of following C code? struct numbers { int x = 2; int y = 3; } int main() { struct numbers nums; nums.x = 110; nums.y = 100; printf("%d\n%d", nums.x, nums.y); return 0; } A. Compile-time Error B. 110 100 C. 2 3 D. Run-time Error 2 points QUESTION 7 What is the output of following C code? typedef struct student { char *stud; }s1; int main() { s1 s; s.stud...
Create a C program to implement a grade book. Must follow these guidelines: 1. Use #define to define MAX_SIZE1 as 20, and MAX_SIZE2 as 10 2. Use typedef to define the following struct type: struct { char name[MAX_SIZE1]; int scores[MAX_SIZE2]; } 3. The program accepts from the comand line an integer n (<= 30) as the number of students in the class. You may assume that the input will always be valid. 4. Dynamically allocate memory for an array of...
Hello, I am having trouble with a problem in my C language class. I am trying to make a program with the following requirements: 1. Use #define to define MAX_SIZE1 as 20, and MAX_SIZE2 as 10 2. Use typedef to define the following struct type: struct { char name[MAX_SIZE1]; int scores[MAX_SIZE2]; } 3. The program accepts from the command line an integer n (<= 30) as the number of students in the class. You may assume that the...
Please Help. C++. Need 3 attributes and 3 methods added to the code below. Need the prototype added to the .h file......and the implementation in the .cpp file....thanks! edited: I just need the above and then I was told to use the methods in the main program; for the vehicle. Any 3 attributes and any three methofds. source.cpp file // Header Comment #include #include #include #include "Automobile.h" using namespace std; struct Address{ string street; string city; string state; string zip;...
in
c++ please
program for this code
#include <iostream>
#include <fstream>
#include <string>
#include <cstring> // for string tokenizer and c-style
string processing
#include <algorithm> // max function
#include <stdlib.h>
#include <time.h>
using namespace std;
// Extend the code here as needed
class BTNode{
private:
int nodeid;
int data;
int levelNum;
BTNode* leftChildPtr;
BTNode* rightChildPtr;
public:
BTNode(){}
void setNodeId(int id){
nodeid = id;
}
int getNodeId(){
return nodeid;
}
void setData(int d){
data = d;
}
int getData(){
return data;...
NEED HELP WITH MY C++ ASSIGNMENT, IT NEEDS TO BE SOLVED USING LISTS #include <iostream> #include <list> #include <map> #include <string> using namespace std; class course { public: string name; int section; int credits; course() {} course(string n, int s, int c) { name = n; section = s; credits = c; } //Add additional needed member functions and implement them. //You also need to implement some needed functions for overloading operator<< . }; //Implement the following functions void add_student(map<int,...