99爱在线视频这里只有精品_窝窝午夜看片成人精品_日韩精品久久久毛片一区二区_亚洲一区二区久久

合肥生活安徽新聞合肥交通合肥房產(chǎn)生活服務(wù)合肥教育合肥招聘合肥旅游文化藝術(shù)合肥美食合肥地圖合肥社保合肥醫(yī)院企業(yè)服務(wù)合肥法律

代做CS 138、C++編程設(shè)計(jì)代寫(xiě)

時(shí)間:2024-05-10  來(lái)源:合肥網(wǎng)hfw.cc  作者:hfw.cc 我要糾錯(cuò)



CS 138 - Sample Final Exam
• The exam is 150 minutes long.
• Please read all instructions carefully.
• There are 4 questions on this exam, some with multiple parts. This exam will be graded out of a
maximum of 104 points.
• The exam is a closed book and notes. You are not permitted to access any electronic devices during
the duration of the exam. You are not allowed to consult another person to find out the answers.
Do not open the exam book without the proctor’s permission. Please make sure to sign the exam
book. Please do not talk among yourselves during the exam. If you have any questions, consult the
proctor. Appropriate university policies will apply if you are caught cheating by the proctor.
• Please write your answers in the appropriate space provided in your respective exam books. Please
make sure to write your names and IDs.
• Solutions will be graded on correctness, clarity, completeness and brevity. Most problems have a
relatively simple solution. Partial solutions may be given partial credit.
• Follow the instructions given by the proctor throughout the exam. If you need to step out of the
exam hall for washroom visits, then please talk to the proctor.
NAME:
Email ID:
Student ID:
In accordance with the letter and the spirit of the University of Waterloo honor code, I pledge
that I will neither give nor receive assistance on this examination.
SIGNATURE:
Problem Max points Points Received
Q1 20
Q2 30
Q3 30
Q4 24
Total 104
1
Question 1: True/False questions (20 points)
·Please specify if the following assertions are True or False. Each sub-question is worth 2 points. For
each question you answer False, justify to get full points.
1. Virtual functions in C++ can be static.
Answer:
2. Hash functions are deterministic, meaning the same input will always produce the same hash code.
Answer:
3. An abstract class in C++ can have both concrete (non-pure virtual) and pure virtual functions.
Answer:
4. C++ allows for function overloading based solely on return type.
Answer:
5. Hash functions must be invertible, allowing the original data to be recovered from its hash code.
Answer:
6. Initializer lists allow for uniform initialization syntax in C++, regardless of whether you are initializing a built-in type or a user-defined type.
Answer:
7. Static methods can be used to modify the state of a static field directly without needing an instance
of the class.
2
Answer:
8. Instantiating a template with a user-defined type requires that the type has specific methods or
behaviors defined.
Answer:
9. The end iterator in C++ points to the last element of a container, allowing direct access to that
element.
Answer:
10. Doubly linked lists guarantee constant-time access to elements at arbitrary positions due to their
bidirectional nature.
Answer:
3
Question 2: Short Answer Questions (30 points)
For each of the sub-questions below, provide a concise, correct, and complete answer. Each sub-question
is worth 5 points.
1. What is the difference between a const pointer and a pointer to a const variable?
Answer:
2. 1: #include <iostream>
2: #include <string>
3: using namespace std;
4:
5: class Vehicle {
6: public:
7: Vehicle();
8: Vehicle(string type);
9: virtual ~Vehicle();
10: void displayType() const;
11: private:
12: string type;
13: };
14:
15: // Method definitions
16: Vehicle::Vehicle() {
17: this->type = "car";
18: }
19:
20: Vehicle::Vehicle(string type) {
21: this->type = type;
22: }
23:
24: Vehicle::~Vehicle() {}
25:
26: void Vehicle::displayType() const {
27: cout << "This is a " << this->type << endl;
28: }
29:
30: int main(int argc, char* argv[]) {
31: Vehicle car {"sedan"};
**: car.displayType();
4
33:
34: Vehicle bike {};
35: bike.displayType();
36:
37: Vehicle* bus = new Vehicle {"bus"};
38: bus->displayType();
39:
40: Vehicle* ptr = bus;
41: ptr->displayType();
42: ptr->type = "truck";
43: ptr->displayType();
44:
45: delete ptr;
46: delete bus;
**:
48: return 0;
49: }
The provided code crashes when executed. Why? Explain your answer. Be specific about where
the problem(s) sites and what exact error(s) will you get.
Answer:
5
3. #include <iostream>
class Circle {
public:
double radius;
double area();
};
double Circle::area() {
return 3.14159 * radius * radius;
}
int main() {
Circle myCircle;
myCircle.radius = 5.0;
std::cout << "The area of the circle is: " << myCircle.area() << std::endl;
return 0;
}
The Circle class does not have a constructor. Do you think this code will execute ? Explain your
answer.
Answer:
4. class Balloon {
public:
...
Balloon (); // Default ctor
Balloon (string shellColour);
Balloon (string c, int size);
Balloon (int i, string c);
...
};
int main (...) {
Balloon rb {"red"};
6
Balloon rbc1 {rb};
}
Will the last line of the main function execute correctly (note that a copy constructor is not defined)?
Answer:
7
5. What are the advantages of using the heap?
Answer:
6. What is the significance of BSTs in terms of the complexity of insertion, deletion and search?
Answer:
8
Question 3 (30 points)
For each of the sub-questions below, provide a concise, correct, and complete answer. Each of the following sub-questions below is worth 6 points.
In class, we learned about different STL container classes. Suppose this time, we want to create our
own implementation of these classes but with some OO inheritance hierarchy. We start with an Abstract
Base Class Sequence for all sequence containers, and a concrete child class Vector. Internally, Vector
uses a dynamic array to store the elements, with an additional field capacity representing this dynamic
array’s size. The field size indicates how many slots are actually being used in the array.
class Sequence {
private:
int size;
protected:
Sequence(): size {0} {}
void setSize(int size) { this -> size = size; }
public:
virtual ~Sequence() {}
virtual string& at(int index) = 0;
virtual void push_back(const string& item) = 0;
virtual void pop_back() = 0;
int getSize() const { return size; }
};
class Vector: public Sequence {
private:
string* theArray;
int capacity;
void increaseCapacity();
public:
Vector();
~Vector();
virtual void push_back(const string& item) override;
virtual void pop_back() override;
virtual string& at(int index) override;
};
string& Vector::at(int index) {
9
if(index >= 0 && index < getSize()) {
return theArray[index];
}
cerr << "Error: Out of bounds" << endl;
assert(false);
}
1. We want our Vector to be able to change its capacity dynamically. To achieve this, Implement
a private helper method increaseCapacity() that allocates a new dynamic array with double
the original capacity, copies the contents of the original array to the new array, replaces the old
array with the new array, and finally disposes of the old array. You may assume the preconditions
capacity > 0 and capacity == size.
Answer:
2. Implement the push back() and pop back() methods for Vector. Both of these methods should
update the field size. When the Vector is full, push back() should call increaseCapacity() before pushing the new item. You don’t need to shrink the capacity in pop back(). You may assume
your increaseCapacity() is implemented correctly.
Answer:
10
3. The implementation of Vector::at() performs bound checking before returning the item at the
given index. We want to perform the same bound checking for all future child classes of Sequence,
but that would require us to implement bound checking for every new child class. We can save this
effort by using the Template Method design pattern:
class Sequence {
private:
// ...
virtual string& getItemAt(int index) = 0; // virtual helper method
protected:
// ...
public:
// ...
string& at(int index); // template method
};
class vector: public Sequence {
private:
// ...
virtual string& getItemAt(int index) override;
public:
// ...
};
We can do the same for push back() and pop back(), but we will leave them as they are for now.
Implement the template method Sequence::at() and the new helper method Vector::getItemAt()
such that calling Vector::at() has the same behaviour as the original.
Answer:
11
4. Let’s implement a new concrete subclass List that uses a linked list.
class List: public Sequence {
private:
struct Node {
string val;
Node* next;
};
Node* head;
virtual string& getItemAt(int index) override;
public:
// ...
virtual void push_back(const string& item) override;
virtual void pop_back() override;
};
Implement the methods of List. You can choose to let the field head point to the “front” or the
“back” of the linked list, as long as you keep it consistent among your methods. You don’t need to
implement the constructor and the destructor. Your implementation shouldn’t leak any memory.
Answer:
5. Now that we have some Sequence classes, let’s use them to implement something else. We can use
the abstract class Sequence to implement a Stack:
template <typename T> class Stack {
private:
12
Sequence* theStack;
public:
Stack(): theStack { new T{} } {}
~Stack() { delete theStack; }
void push(const string& value);
void pop();
string top() const;
bool isEmpty();
};
Note that assigning new T to theStack in the constructor forces T to be a concrete sub-type of
Sequence. (We will assume that all subclass of Sequence has a default constructor.)
Implement the remaining methods. Since Sequence::at() already does bound checking, you don’t
need to do it again when you use it here. You may also assume that T::pop back() will abort via
assertion if the Sequence is empty.
Answer:
13
Question 4 (24 points)
For each of the sub-questions below, provide a concise, correct, and complete answer. Each of the following sub-questions below is worth 6 points.
In this question, we will start from an abstract base class Sequence and extend it to a Deque (doubleended queue). A deque is a more complex sequence container that allows insertion and removal of elements
from both the front and the back. For this implementation, internally, Deque will utilize a dynamic array
to manage its elements, similar to Vector, but with the capability to efficiently add or remove elements
at both ends. Starting with the Sequence abstract base class, we will focus on implementing the Deque
class with the necessary modifications to support dynamic resizing and double-ended operations.
class Sequence {
private:
int size;
protected:
Sequence(): size {0} {}
void setSize(int size) { this -> size = size; }
public:
virtual ~Sequence() {}
virtual string& at(int index) = 0;
virtual void push_back(const string& item) = 0;
virtual void pop_back() = 0;
int getSize() const { return size; }
};
class Deque : public Sequence {
private:
std::string* theArray;
int capacity;
int front; // Index of the front element
int rear; // Index just past the last element
void increaseCapacity();
public:
Deque();
~Deque();
void push_front(const std::string& item);
void pop_front();
virtual void push_back(const std::string& item) override;
virtual void pop_back() override;
14
virtual std::string& at(int index) override;
};
1. Implementing increaseCapacity() for Deque: To support dynamic resizing, especially when either
front or rear operations exceed the current capacity, you are asked to implement increaseCapacity().
This method is expected to double the capacity of the deque, properly repositioning elements to
maintain the deque’s order. You are expected to place the elements in the original deque at the
center of the new dequeue to account for insertion in both front and rear of the dequeue.
2. Your second task is to implement double-ended operations push front, pop front, push back and
pop back: These methods adjust the class variables front and rear accordingly. They also call
increaseCapacity() when necessary.
Answer:
15
3. Please adjust the at() method for Deque: Given Deque’s dynamic resizing and double-ended nature, its at() method must consider the front index’s offset when accessing elements.
Answer:
16
4. Lastly, proper resource management is crucial, especially for dynamic array allocation. Please implement the constructor and destructor of Deque. Please implement the constructor as no input
parameters but assume the class receives a default value for the deque capacity of 16.
Answer:
請(qǐng)加QQ:99515681  郵箱:99515681@qq.com   WX:codinghelp






 

掃一掃在手機(jī)打開(kāi)當(dāng)前頁(yè)
  • 上一篇:代做INFO1113、代寫(xiě)Java編程語(yǔ)言
  • 下一篇:福州去泰國(guó)大學(xué)留學(xué)需要辦簽證嗎(福州可以去哪辦理留學(xué)簽)
  • 無(wú)相關(guān)信息
    合肥生活資訊

    合肥圖文信息
    急尋熱仿真分析?代做熱仿真服務(wù)+熱設(shè)計(jì)優(yōu)化
    急尋熱仿真分析?代做熱仿真服務(wù)+熱設(shè)計(jì)優(yōu)化
    出評(píng) 開(kāi)團(tuán)工具
    出評(píng) 開(kāi)團(tuán)工具
    挖掘機(jī)濾芯提升發(fā)動(dòng)機(jī)性能
    挖掘機(jī)濾芯提升發(fā)動(dòng)機(jī)性能
    海信羅馬假日洗衣機(jī)亮相AWE  復(fù)古美學(xué)與現(xiàn)代科技完美結(jié)合
    海信羅馬假日洗衣機(jī)亮相AWE 復(fù)古美學(xué)與現(xiàn)代
    合肥機(jī)場(chǎng)巴士4號(hào)線
    合肥機(jī)場(chǎng)巴士4號(hào)線
    合肥機(jī)場(chǎng)巴士3號(hào)線
    合肥機(jī)場(chǎng)巴士3號(hào)線
    合肥機(jī)場(chǎng)巴士2號(hào)線
    合肥機(jī)場(chǎng)巴士2號(hào)線
    合肥機(jī)場(chǎng)巴士1號(hào)線
    合肥機(jī)場(chǎng)巴士1號(hào)線
  • 短信驗(yàn)證碼 豆包 幣安下載 AI生圖 目錄網(wǎng)

    關(guān)于我們 | 打賞支持 | 廣告服務(wù) | 聯(lián)系我們 | 網(wǎng)站地圖 | 免責(zé)聲明 | 幫助中心 | 友情鏈接 |

    Copyright © 2025 hfw.cc Inc. All Rights Reserved. 合肥網(wǎng) 版權(quán)所有
    ICP備06013414號(hào)-3 公安備 42010502001045

    99爱在线视频这里只有精品_窝窝午夜看片成人精品_日韩精品久久久毛片一区二区_亚洲一区二区久久

          9000px;">

                亚洲免费色视频| 久久午夜老司机| 国产+成+人+亚洲欧洲自线| 99精品桃花视频在线观看| 欧美日韩国产精品自在自线| 久久伊人中文字幕| 亚洲视频一区在线| 麻豆精品在线视频| 色哟哟国产精品| www精品美女久久久tv| 亚洲午夜免费视频| 国产精品一区二区你懂的| 色悠久久久久综合欧美99| 久久一留热品黄| 一区二区三区中文在线| 国模娜娜一区二区三区| 精品视频在线看| 中文字幕一区视频| 麻豆一区二区在线| 欧美三级日韩在线| 中文字幕亚洲成人| 国产乱淫av一区二区三区| 欧美日韩亚洲国产综合| 17c精品麻豆一区二区免费| 美女久久久精品| 717成人午夜免费福利电影| 一区二区成人在线| 成人黄色电影在线| 久久蜜桃av一区精品变态类天堂| 美女尤物国产一区| 欧美丰满一区二区免费视频| 久久精品亚洲一区二区三区浴池| 欧美在线观看视频一区二区 | 在线观看一区日韩| 久久久精品欧美丰满| 日韩电影免费在线观看网站| 91久久精品一区二区三区| 中文天堂在线一区| 国产成人aaa| 国产日韩精品一区二区三区| 国产露脸91国语对白| 亚洲精品一区二区三区精华液| 亚洲一二三四在线| 国产精品少妇自拍| 激情五月激情综合网| 精品日韩成人av| 国产综合久久久久久鬼色| 欧美一区日韩一区| 裸体在线国模精品偷拍| 日韩欧美国产综合| 黄色日韩三级电影| 日本一区二区动态图| 成人av午夜电影| 亚洲黄色免费电影| 蜜臀av性久久久久蜜臀aⅴ| 国产精品理伦片| 天天免费综合色| 亚洲欧洲国产日韩| 欧美综合视频在线观看| 性欧美大战久久久久久久久| 一区二区欧美在线观看| 欧美一a一片一级一片| 一级日本不卡的影视| 欧美性大战久久久久久久蜜臀 | 波多野结衣亚洲一区| 国产日韩欧美精品电影三级在线| 一区二区三区四区乱视频| 色噜噜偷拍精品综合在线| 天天综合日日夜夜精品| 日韩午夜激情电影| 粉嫩aⅴ一区二区三区四区| 亚洲人成在线观看一区二区| 欧美性三三影院| 精品久久国产字幕高潮| 国产成a人无v码亚洲福利| 一区二区三区毛片| 精品国产污污免费网站入口| 亚洲成人av一区二区| 久久这里都是精品| 99视频热这里只有精品免费| 午夜亚洲福利老司机| 国产日韩欧美a| 日本福利一区二区| 麻豆国产精品一区二区三区 | 欧美吻胸吃奶大尺度电影| 日本va欧美va精品发布| 国产女人18水真多18精品一级做 | 青青草97国产精品免费观看 | 欧美亚洲愉拍一区二区| 精品一区二区三区视频在线观看| 在线欧美日韩精品| 狠狠v欧美v日韩v亚洲ⅴ| 亚洲视频综合在线| 日韩一区二区三区高清免费看看| 日本美女一区二区三区视频| 国产无人区一区二区三区| 欧美日精品一区视频| 成人美女视频在线观看| 狠狠色综合播放一区二区| 亚洲国产sm捆绑调教视频 | 欧美亚洲图片小说| 激情欧美日韩一区二区| 亚洲与欧洲av电影| 国产日韩高清在线| 欧美va亚洲va| 9191国产精品| 日本乱人伦aⅴ精品| 99re免费视频精品全部| 日韩黄色免费电影| 国产亚洲女人久久久久毛片| 欧美日韩一区二区不卡| 色综合天天天天做夜夜夜夜做| 日本一区二区免费在线| 56国语精品自产拍在线观看| 91美女视频网站| 日韩欧美一级特黄在线播放| 亚洲国产精品自拍| 欧美一级片免费看| 亚洲视频一区在线观看| 欧美大片一区二区三区| 欧美视频自拍偷拍| 色婷婷精品久久二区二区蜜臀av| 欧美国产综合色视频| 欧美va日韩va| 91精品国产综合久久香蕉的特点| 经典三级一区二区| 日韩中文字幕麻豆| 亚洲精品中文在线| 亚洲精品视频自拍| 亚洲综合在线免费观看| 亚洲一区二区三区自拍| 亚洲一卡二卡三卡四卡五卡| 亚洲自拍偷拍综合| 亚洲一区影音先锋| 天天色综合天天| 麻豆传媒一区二区三区| 精品一区二区三区欧美| 黄色成人免费在线| 粉嫩蜜臀av国产精品网站| 99久久er热在这里只有精品15| 视频一区二区国产| 美国三级日本三级久久99 | 欧美精品久久一区二区三区| 欧美日韩国产精品自在自线| 欧美偷拍一区二区| 在线播放中文一区| 欧美精品一区二区三区在线播放 | 日韩影院免费视频| 天天爽夜夜爽夜夜爽精品视频| 中文字幕亚洲不卡| 夜夜精品视频一区二区 | 一区视频在线播放| 亚洲手机成人高清视频| 亚洲444eee在线观看| 麻豆高清免费国产一区| 国产91色综合久久免费分享| 91久久精品日日躁夜夜躁欧美| 久久66热re国产| 国产大陆亚洲精品国产| 成人福利电影精品一区二区在线观看| 视频在线观看91| 国产在线一区二区| 色呦呦网站一区| 日韩欧美成人一区| 国产精品久99| 日韩av一级片| 成人app在线观看| 欧美电影一区二区| 国产精品福利影院| 石原莉奈在线亚洲二区| 成人avav影音| 欧美色男人天堂| 欧美国产日产图区| 天堂av在线一区| 丁香六月久久综合狠狠色| 在线综合亚洲欧美在线视频| 国产精品久久毛片av大全日韩| 色综合久久99| 精品999在线播放| 久久精品国产99久久6| 成人高清伦理免费影院在线观看| 国产一区二区三区国产| 国产福利视频一区二区三区| 日本道免费精品一区二区三区| 国产精品亚洲视频| 日本道精品一区二区三区| 久久午夜色播影院免费高清| 性欧美疯狂xxxxbbbb| 99久久99久久久精品齐齐| 久久精品水蜜桃av综合天堂| 五月天一区二区三区| 97精品国产97久久久久久久久久久久| 本田岬高潮一区二区三区| 日韩精品一区二区三区在线| 亚洲成av人影院在线观看网| 91视频观看视频| 国产精品国产三级国产aⅴ无密码| 中文字幕一区二区三区四区| 九九视频精品免费| 欧美电影影音先锋|