联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> C/C++编程C/C++编程

日期:2020-11-03 11:19

Question 2 (20 points)

Write a C program that would allow for the user to enter 3 words and for each word it would dynamically

allocate a character array of size equal to the length of the entered word. The array would then be used to

store each individual character of the entered word. Your program should contain a function called

create_char_array with the following prototype:

char *create_char_array(int array_size);

Where array_size is the size of the character array and the return variable (char *) is a pointer to

dynamically allocated array.

Question 3 (20 points)

Write a C program that would compute the mean and variance over an array of decimal values entered by

the user. In this program the user is asked to provide the number of values that are in their dataset. Based

on the entered number you should create a double array of the appropriate size that would allow you to

1

store each value. Afterwards the user should be asked to enter each value individually. Once all values are

entered you program should compute the mean and variance of the dataset and output both values into a

file named data_mv.txt. Your program should contain a function called compute_mv that should be

used to compute the mean and variance of the dataset. The function should have the following prototype:


double *compute_mv(double *pd, int len);

Where *pd is the pointer to the double array that contains the dataset and len is the length of the array.

The function should return a pointer (double *) to a double array that contains the mean and the variance.

Question 4 (40 points)

Write a C++ program that will manage the homework and exam grades of the students in our class. The

program should use a class named Student to store each student’s information. More specifically, for

each student it should store the following information:

• first_name – string (public)

• last_name – string (public)

• SSN – int (private)

• UNI – int (public)

• homework – int array of size 5 that stores each homework score (private)

• midterm – int (private)

• final – int (private)

• grade – string (private)

• password – string (private)

The class should be constructed by providing the student first and last name and their UNI. During

construction all homework and exam scores should be initialized to zero. In addition, the password variable

should be hard coded (i.e. specified in the code).

The class should include the following functions:

• SetSSN(int ssn) – Sets the student SSN (public)

• GetMidtermExam(string pwd) – returns the midterm score if the correct password is

specified (public)

• SetMidtermExam(string pwd, int score) – assigns the midterm score if the correct

password is specified (public)

• GetFinalExam(string pwd) – returns the final exam score if the correct password is

specified (public)

• SetFinalExam(string pwd, int score) – assigns the final exam score if the correct

password is specified (public)

• SetHomeworkScore(string pwd, int i, int score) – Sets the score of the i-th

homework if the correct password is specified (public)

• GetHomeworkScore(string pwd, int i) – Gets the score of the i-th homework if the

correct password is specified (public)

• ComputeAvgHomework() – This function should go over the homework scores stored in the

homework array, compute and return the mean of the top 4 homework scores (private)

• GetAllStudentScores(string pwd) – Returns the following values: the midterm and

final exam scores, the 5 homework scores, the average of the 5 homework scores, and the average

score of the top 4 homework scores if the correct password is specified (public)

• AssignFinalGrade(string pwd, string grade) – sets the final student grade if the

correct password is specified (public)

• GetFinalGrade (string pwd) – Returns the final grade of the student if the correct

password is provided (public)

Note that for each of the class member variable and function outlined above, their access modifier is

specified in parentheses.


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp