Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For the coding problems, you will be asked by this type of offline questions in

ID: 3539249 • Letter: F

Question

For the coding problems, you will be asked by this type of offline questions in Exam1. You need to write your codes in Visual Studio or any other text editors such as notepad on Window, TextEdit on Mac. You do not need to compile but do need to write them in correct C++ syntax, and make sure to upload the right TEXT files for the questions.

(1) Create a new header file Student.h and write the prototype of a class Student includes the private portion consisting of an integer for ID and a static char array for name. Then, add appropriate operations such as below to the classes:

Student();

Student(char name[], int id);

void print(ostream & out);

int get_id() const;

void set_name(char new_name[]);

(2) Implement the class methods in the same file Student.h.

(3) Write a driver (or client with main function in a new file main.cpp) to do the following: (a) declare two students A and B, A has default name and id; and B%u2019s name is %u201CJoe%u201D and id is 999999999. (b) Check if student B%u2019s id is 999999999, print %u201Ccorrect%u201D if it is and %u201Cincorrect%u201D if it is not on screen. (c) Print student B%u2019s id and name on screen (d) Change the name of student A to %u201CAnonymous%u201D.

Answer the following questions based on the following codes,

Use a for statement to print the elements of array numbers using pointer/offset notation with the array name as the pointer.

3Write two different statements that each assign the starting address of array numbers to the pointer variable ptr.

4Write an expression that uses ptr to copy element 3 of the array to element 4. Do not use numbers in your answer.

It returns a pointer to the first instance of string s2 in s1, returns a NULL pointer if s2 is not encountered in s1.


Answer the following questions based on the following codes:

Assume the declarations

xamine the following declarations for a dynamic array-based implementation for the Stack ADT.

Explanation / Answer


public class Student {

private String name;

private String year;

private double gpa;


// 1) Make a HashMap called history that maps String (course name) to Character (grade attained)


HashMap<String,Character> history = new HashMap<String,Character>();


/*

2) Make a constructor that takes 5 parameters: a String (name of student), a String (year of

Student), a double (gpa of Student), an array of String (courses taken) and an array of

Character (grades attained in courses) and use the parameters to set the name, year, gpa

and to add the entries of the HashMap.

*/


public Student(String name,String year, double gpa, String[] courses,char[] grades){

this.name = name;

this.year = year;

this.gpa = gpa;

int i;

int length = courses.length;

for(i=0;i<length;i++){

history.put(courses[i], grades[i]);

}

}

// 3) Make a getter for the Student name.


public String getName(){

return name;

}

/*

4) Make a getter called getGrade that has a parameter of type String (the course) and that returns

a Character (the grade attained on that course) from the HashMap.

*/

public char getGrade(String course){

return history.get(course);

}


// 5) Make a toString method to return: Name: xxxxxx Year: xxxxx


public String toString(){

return "Name: " + name + " Year: " + year + " ";

}

}