CS代考计算机代写 c# c++ CPSC 3200 Object-Oriented Development Midterm

CPSC 3200 Object-Oriented Development Midterm
Wednesday September 14, 2020 1230p – 2pm

TYPE ANSWERS, including verification of academic integrity, in downloaded document
UPLOAD YOUR FINISHED DOCUMENT TO CANVAS before the deadline

BY PROVIDING MY EMAIL BELOW, I VERIFY THAT I HAVE:
• Completed this exam on my own, without assistance from any other(s)
• Consulted only permissible sources:
class material posted on Canvas, textbook, my own personal notes
• NOT consulted any other external source(s)

email:_____________________________________

To receive partial credit, REMEMBER TO SHOW ALL YOUR WORK.

DO NOT comment extensively.
DO NOT give elaborate I/O messages due to the time constraint of this test.
DO NOT implement obvious functions (such as sort, swap and standard constructors)

BUDGET your time: spend more time on problems worth more.

STATE ALL YOUR ASSUMPTIONS

DO NOT use STL, vectors, etc.

I
15

II
20

III
30

IV
25

V
10

total
100

• (15 points) Given the following C# code
• Convert the code to comparable C++ code
• Comment on C++ client expectations, if any, for the yNot class design
• Comment on any relevant language differences between C# and C++

yNot seedDB(uint seed, uint size)
{ if (size == 0 || seed > size) return null;

yNot[] myDB = new yNot[size];
for (int k = 0; k < size; k++) myDB[k] = new yNot(seed*k); yNot minObj = myDB[0]; int min = myDB[0].getValue(); for (int k = 1; k < size; k++) { int update = myDB[k].getValue(); if ( update < min) { min = update; minObj = myDB[k]; } } return minObj; } class yNot { public: yNot(int v) { value = v; } int getValue() { return value; } private: int value; }; yNot *myDB[10]; yNot *seedDB(size_t seed, size_t size)//return type is a pointer { if(size==0||seed>size)
{
return nullptr;//C# use null, C++ use nullptr;
}
for(size_t k = 0;kgetValue();//use->, not .
for(int k = 1;kgetValue();//use ->, not .
if(update THRESHOLD;
}
}

• (30 points) Design a C++ class cCheck that encapsulates an array of numbers and:
• returns the kth number from the array upon the kth query(), for example:
If the array is [7, 14, 25, 15]
the first call to query() returns 7, the second call returns 14,…
• when the last number in the array is returned from query()
resets the query count
expands the array: e.g. [7, 14, 25, 15] becomes, say, [7, 14, 25, 15, 35]
• supports replacing the encapsulated array only if the replacement is not smaller
• supports efficient, deep copying

Define this class, providing all implementation details.
You must use arrays and may not use another container (such as vector).

class cCheck
{
public:
cCheck(int *array, int size){
count = 0;
this->size = size;
this->array = array;
}

cCheck(const cCheck& check){
this->count = check.count;
this->size = checl.size;
this->array = new int[this->size];
for(size_t i=0;iarray[i] = check.array[i];
}
}

cCheck& operator=(cCheck& check)
{
if(this->array!=nullptr)
{
delete[] this->array;
}
this->count = check.count;
this->size = check.size;
this->array = new int[size];
for(int i=0;isize;i++)
{
this->array[i]=check.array[i];
}
return *this;
}

~cCheck()
{
if(this->array!=nullptr){
delete[] this->array;
this->array = nullptr;
}
}

void replace(int* p, size_t size){
if(size>=this->size){
delete[] this->array;
this->size = size;
this->array = new int[size];
for(int i=0;isize;i++){
this->array[i]=p[i];
}
}
}

int query(){
int v = kth(++count);
if(count==size){
count = 0;
int expand = kth(size)+kth(size-1);
int* p = new int[++size];
for(size_t i=0;iarray = p;
}
return v;
}

private:
int kth(int k){
int v = INT_MIN;
for(;k>);k–){
for(int i = 0;i start

class expoG: getNum() returns k*k*start for the kth query
replace(q)
replaces start only if the number of active/inactive transitions is < q Define the class(es), providing all implementation details, including active/inactive state transitions class simple{ public: simpleG(int start){ this->start = start;
count=0;
}

virtual int getNum(){
int v = (count++) * start;
if(!isActive()){
return -1;
}
return v;
}

virtual void replace(int q)=0;

bool is Active(){
return count <=MAX_COUNT; } void reset(){ count=0; } protected: int count; int start; int MAX_COUNT = 100; }; Class oscillateG : simple{ public:
 oscillateG(int start):simple(start){ } virtual int getNum(){ if(count % 2!=0){ return simpleG::getNum(); } return simpleG::getNum() * -1; } virtual void replace(int q){ if(q>start){
start=q;
}
}
};

class expoG : simpleG{
public:
expoG(int start):simpleG(start){
}

virtual int getNum(){
int v = count * count * start;
count++;
if(!isActive()){
return -1;
}
return v;
}

virtual void replace(int q){
if(q