国产人妻人伦精品_欧美一区二区三区图_亚洲欧洲久久_日韩美女av在线免费观看

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

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

時(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、代寫Java編程語(yǔ)言
  • 下一篇:福州去泰國(guó)大學(xué)留學(xué)需要辦簽證嗎(福州可以去哪辦理留學(xué)簽)
  • 無(wú)相關(guān)信息
    合肥生活資訊

    合肥圖文信息
    流體仿真外包多少錢_專業(yè)CFD分析代做_友商科技CAE仿真
    流體仿真外包多少錢_專業(yè)CFD分析代做_友商科
    CAE仿真分析代做公司 CFD流體仿真服務(wù) 管路流場(chǎng)仿真外包
    CAE仿真分析代做公司 CFD流體仿真服務(wù) 管路
    流體CFD仿真分析_代做咨詢服務(wù)_Fluent 仿真技術(shù)服務(wù)
    流體CFD仿真分析_代做咨詢服務(wù)_Fluent 仿真
    結(jié)構(gòu)仿真分析服務(wù)_CAE代做咨詢外包_剛強(qiáng)度疲勞振動(dòng)
    結(jié)構(gòu)仿真分析服務(wù)_CAE代做咨詢外包_剛強(qiáng)度疲
    流體cfd仿真分析服務(wù) 7類仿真分析代做服務(wù)40個(gè)行業(yè)
    流體cfd仿真分析服務(wù) 7類仿真分析代做服務(wù)4
    超全面的拼多多電商運(yùn)營(yíng)技巧,多多開(kāi)團(tuán)助手,多多出評(píng)軟件徽y1698861
    超全面的拼多多電商運(yùn)營(yíng)技巧,多多開(kāi)團(tuán)助手
    CAE有限元仿真分析團(tuán)隊(duì),2026仿真代做咨詢服務(wù)平臺(tái)
    CAE有限元仿真分析團(tuán)隊(duì),2026仿真代做咨詢服
    釘釘簽到打卡位置修改神器,2026怎么修改定位在范圍內(nèi)
    釘釘簽到打卡位置修改神器,2026怎么修改定
  • 短信驗(yàn)證碼 寵物飼養(yǎng) 十大衛(wèi)浴品牌排行 suno 豆包網(wǎng)頁(yè)版入口 wps 目錄網(wǎng) 排行網(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

    国产人妻人伦精品_欧美一区二区三区图_亚洲欧洲久久_日韩美女av在线免费观看
    久久偷窥视频| 99中文字幕在线观看| 亚洲熟妇无码一区二区三区| 欧美亚洲视频在线观看| www国产黄色| 久久视频在线观看免费| 日本久久久网站| 国产午夜福利在线播放| 色琪琪综合男人的天堂aⅴ视频| 国产精品视频大全| 日韩av电影国产| 99热国产免费| 欧美精品情趣视频| 日韩av色综合| 粉嫩精品一区二区三区在线观看 | 国内精品小视频在线观看| 久久久久久久网站| 午夜精品视频网站| 国产伦精品一区二区三区| 国产精品美女在线观看| 日韩国产欧美亚洲| 成人黄色一区二区| 欧美人成在线视频| 国产精品一区二区三区免费| 精品久久久无码人妻字幂| 男人天堂新网址| 国产精品久久激情| 欧日韩一区二区三区| 久久久精品在线视频| 在线视频不卡国产| 久久久一本二本三本| 午夜精品在线视频| 久久久免费观看| 日韩欧美一区二区视频在线播放| 久久乐国产精品| 日本一区不卡| 日本国产在线播放| 九九久久99| 人妻久久久一区二区三区| 久久久婷婷一区二区三区不卡| 亚洲免费久久| 成人在线免费观看一区| 欧美日韩电影在线观看| 国语自产精品视频在线看一大j8| 久久色精品视频| 欧美日韩免费高清| 久久综合伊人77777尤物| 欧美日韩国产三区| 国产精品久久久久久久av电影 | 九九精品视频在线| 国产在线播放91| 欧美人与物videos| av免费观看国产| 日韩资源av在线| 久久国产精品视频在线观看| 免费看黄色a级片| 欧美xxxx18性欧美| 国产精品香蕉国产| 视频一区二区视频| 色999日韩欧美国产| 亚州国产精品久久久| 久久久久福利视频| 国产精品成人一区二区三区| 国产精品麻豆va在线播放| 国产不卡一区二区三区在线观看| 岛国视频一区免费观看| 一区二区三区我不卡| 久久最新资源网| 国产精品久久电影观看| 俄罗斯精品一区二区三区| 68精品国产免费久久久久久婷婷| 国产乱子伦精品无码专区| 九色成人免费视频| y97精品国产97久久久久久| 日韩视频亚洲视频| 久久精品久久久久久国产 免费| 久草综合在线观看| 久久国产精品免费一区| 国产精品香蕉视屏| wwwwww欧美| 97人人香蕉| av动漫在线免费观看| 高清欧美性猛交xxxx| 国产精品亚洲精品| 久久久综合av| 国产精品一区二区久久国产 | 国产精品观看在线亚洲人成网| 久久亚洲精品一区| 久久黄色av网站| 久久久成人精品| 综合色婷婷一区二区亚洲欧美国产| 欧美日韩国产va另类| 国产精品福利片| 国产精品无码电影在线观看| 久久精品国产99精品国产亚洲性色 | 国产精品日韩三级| 日韩中文字幕网站| 久久久久久国产三级电影| 日韩中文字幕在线播放| 国产精品18毛片一区二区| 91精品国产高清久久久久久| 久久免费在线观看| 久久久久久有精品国产| 日韩中文字幕网| 久久人人爽亚洲精品天堂| 99免费在线视频观看| 久久综合久久88| 色婷婷久久一区二区| 91久久精品国产| 国产九九精品视频| 国产视频一区二区三区四区| 欧洲成人免费视频| 日韩精品一区二区三区色欲av| 午夜精品久久久99热福利| 九九久久综合网站| 九九综合九九综合| 久久国产天堂福利天堂| 国产精品成人免费视频| 国产精品久久久久久久乖乖| 国产精品久久久久久久久久尿| 国产精品免费一区二区三区观看| 国产精品沙发午睡系列| 日韩在线观看高清| 久久精品一本久久99精品| 久久久精品2019中文字幕神马| www.亚洲免费视频| 国产精品久久久久久久久免费 | 亚洲v日韩v欧美v综合| 亚洲熟妇无码一区二区三区| 亚洲一区二区三区四区中文| 亚洲国产婷婷香蕉久久久久久99| 午夜免费福利小电影| 日本伊人精品一区二区三区介绍| 色一情一乱一伦一区二区三区| 肉大捧一出免费观看网站在线播放| 日本一区不卡| 欧美无砖专区免费| 国内精品400部情侣激情| 欧美精品卡一卡二| 黄色大片在线免费看| 国内精品**久久毛片app| 国产欧美在线播放| 91久久嫩草影院一区二区| 久久男人的天堂| 久久精品久久久久久国产 免费| 国产精品久久7| 色综合视频网站| 午夜免费在线观看精品视频| 热门国产精品亚洲第一区在线| 精品日产一区2区三区黄免费| 国产情侣第一页| 91精品国产高清久久久久久久久| 久久琪琪电影院| 久久99精品久久久久久秒播放器 | 国产精品专区h在线观看| 91久久国产自产拍夜夜嗨| 久久久久久国产三级电影| 精品乱子伦一区二区三区| 手机在线观看国产精品| 今天免费高清在线观看国语| 国产精品一区二区女厕厕| 国产成人福利网站| 久久精品亚洲一区| 中文字幕人成一区| 秋霞成人午夜鲁丝一区二区三区| 国产专区在线视频| 久久青青草原一区二区| 国产精品视频在线免费观看| 色综合久久中文字幕综合网小说| 日本在线视频不卡| 国产奶头好大揉着好爽视频| 国产va免费精品高清在线| 国产精品久久久久99| 亚洲xxxx视频| 国产资源第一页| 久久国产精品-国产精品| 久久99青青精品免费观看| 日韩亚洲一区在线播放| 欧美日韩精品一区| 成人国产精品久久久| 久久久久综合一区二区三区| 国产999视频| 欧美中日韩免费视频| 成人av免费电影| 国产精品毛片va一区二区三区| 午夜啪啪福利视频| 国产天堂视频在线观看| 色噜噜亚洲精品中文字幕| 在线观看日本一区| 蜜桃免费区二区三区| 久久精品网站视频| 亚洲一区三区电影在线观看| 国产小视频免费| 久久久久久久一| 亚洲精品一品区二品区三品区| 美女精品国产| 精品国产一区二区三区久久狼黑人| 亚洲精品日韩成人| 国产毛片视频网站| 国产精品久久婷婷六月丁香|