Spring 2016 Lab 4 or all programs, please define separate ), list declarations i
ID: 3684452 • Letter: S
Question
Spring 2016 Lab 4 or all programs, please define separate ), list declarations in header Your fourth lab will focus on struct and pointer header file and source files for the functions except main),list files, and function in and pointer. F mplementation in source files. The tasksi 1. a. Using C/C++, define a struct Student which has three properties nd , a ruct Student which has three properties: id, score n integer type, score is in double tvpe, and grade is in char typ grade. id is in integer type, score is in double type, and grade Student to declare an array with 20 elements in main0: ie from 1 to 20; assign the scores of each student with random define a function and pass the student array as parameter(s). In in main); assign the ids of the students the grade of each student according to his scores (e.g. if score is grade: else if score is >=80, assign-B' grade; else if score is >=70, as score is >-60, assign 'D'; otherwise, assign· students' ids, scores, and grades accordingly ray as parameter(s). In the function, assign sign 'C'; else if within [10, 99]; then cores (e.g. if score is >-90, assign 'A F); after the function returns, print all b. redefine the function to assign grades, but change it to a recursive one 2. Using C/C++, define an integer pointer in main0, and use this pointer to dynamically allocate an integer array with 50 elements; assign the array with random numbers in range [0, 999]. Then, pass the array as parameter(s) to a function prime_count() which counts the number of the integers that are prime, and prints those integers; after the function call, print the "counter" result; finally, remember to use delete to deallocate the array memories. Note that you need to define a Boolean function prime() which judges whether a integer is prime or not. This function will be called and used by prime_ count) to tell whether the numbers in the array are prime or not. In this homework, you need to find a classmate to form a study group and use pair programming method to help each enhance programming skills: for each program one will write the program (driver) and the other will verify if the writing is correct or not (navigator). Note that you need to take turns to write and verify (e.g. in program 1 person A writes the code and person B checks it, in program 2, person B writes th code and person A checks it). Please state clearly in the comments who typed th code and who checked and tested in each program The following specifications will be expected for each of your projects for this ci create new source 1. An empty project file must be created first, and then you will create new file and header files Add comments at the beginning of the program, and add description unction, loop, etc description for each 2. including all cpp and h file codould be written on the upper your source code, includ ur name, your ID number and lab number should b ht-hand corner of the top sheet of the hardcopy. Note tinten on tand h m in both the hardoopy ang umbopy of your source code. ndluding a Note that you are required you are pper ouse assig o submit your softcopy through homework 4 link in ec 1 a2)in Taskstream.
Explanation / Answer
1)
#include<stdio.h>
#include<stdlib.h>
struct Student
{
int id;
double score;
char grade;
};
char grade(double[]);
void main()
{
struct Student s[20];
int i;
//assigning id's
for(i=1;s[i]<=20;i++)
{
s[i].id=i;
}
//random numbers generating from 10 to 99
for(i=1; i<=20;i++)
{
s[i].score=rand()%10+90;
}
//providing grades to each student
for(i=1;i<=20;i++)
{
s[i].grade=grade(s[i].score);
}
//printing all student id's scores and grades
for(i=1;i<=20;i++)
{
printf("Student Id "+ s.id[i]+"Student Score"+s.score[i]+"Student Grade"+s.grade);
}
}
char grade(double s)
{
char g;
if(s>=90)
g='A';
else
if(s>=80)
g='B';
else
if(s>=70)
g='C';
else
if(s>=60)
g='D';
else
g='F';
return g;
}
2)
#include<math.h>
#include<stdio.h>
#include<sdlib.h>
int prime_count(int[]);
bool prime();
void main();
{
int a[50];
int *p;
int i;
int c;
p=a;
//providing random numbers to an array
for(i=1;i<=50;i++)
{
a[i]=rand()%0+999;
}
int c=prime_count(int a[]);
printf( "the total prime numbers are"+c);
}
//counting of prime numbers
int prime_count(int a[])
{
int i;
int c;
for(i=1;<i<=50;i++)
{
if(prime(a[i])
{
c++;
printf(a[i]+"is a prime number");
}
}
return c;
}
// prime function
bool prime(int a)
{
int c=0;
for(j=2;j<a[i];j++)
{
if(a[i]%j==0)
{
return false;
}
}
return true;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.