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

合肥生活安徽新聞合肥交通合肥房產生活服務合肥教育合肥招聘合肥旅游文化藝術合肥美食合肥地圖合肥社保合肥醫院企業服務合肥法律

代做CS 138、C++編程設計代寫

時間:2024-05-10  來源:合肥網hfw.cc  作者:hfw.cc 我要糾錯



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:
請加QQ:99515681  郵箱:99515681@qq.com   WX:codinghelp






 

掃一掃在手機打開當前頁
  • 上一篇:代做INFO1113、代寫Java編程語言
  • 下一篇:福州去泰國大學留學需要辦簽證嗎(福州可以去哪辦理留學簽)
  • 無相關信息
    合肥生活資訊

    合肥圖文信息
    流體仿真外包多少錢_專業CFD分析代做_友商科技CAE仿真
    流體仿真外包多少錢_專業CFD分析代做_友商科
    CAE仿真分析代做公司 CFD流體仿真服務 管路流場仿真外包
    CAE仿真分析代做公司 CFD流體仿真服務 管路
    流體CFD仿真分析_代做咨詢服務_Fluent 仿真技術服務
    流體CFD仿真分析_代做咨詢服務_Fluent 仿真
    結構仿真分析服務_CAE代做咨詢外包_剛強度疲勞振動
    結構仿真分析服務_CAE代做咨詢外包_剛強度疲
    流體cfd仿真分析服務 7類仿真分析代做服務40個行業
    流體cfd仿真分析服務 7類仿真分析代做服務4
    超全面的拼多多電商運營技巧,多多開團助手,多多出評軟件徽y1698861
    超全面的拼多多電商運營技巧,多多開團助手
    CAE有限元仿真分析團隊,2026仿真代做咨詢服務平臺
    CAE有限元仿真分析團隊,2026仿真代做咨詢服
    釘釘簽到打卡位置修改神器,2026怎么修改定位在范圍內
    釘釘簽到打卡位置修改神器,2026怎么修改定
  • 短信驗證碼 豆包網頁版入口 破天一劍 目錄網 排行網

    關于我們 | 打賞支持 | 廣告服務 | 聯系我們 | 網站地圖 | 免責聲明 | 幫助中心 | 友情鏈接 |

    Copyright © 2025 hfw.cc Inc. All Rights Reserved. 合肥網 版權所有
    ICP備06013414號-3 公安備 42010502001045

    国产人妻人伦精品_欧美一区二区三区图_亚洲欧洲久久_日韩美女av在线免费观看
    九色91国产| 久久精品视频在线| 免费看又黄又无码的网站| 欧美一区二区三区精品电影| 久久国产精品影视| 九九精品在线视频| 美女精品视频一区| 欧美激情一区二区三区高清视频| 国产精品极品在线| 久久av红桃一区二区小说| 国产精品视频在线观看| 国产精品入口日韩视频大尺度 | 一区二区免费电影| 日韩一区二区三区高清| 日本不卡免费新一二三区| 日韩理论片在线观看| 欧美一区在线直播| 国产一区亚洲二区三区| www.av一区视频| 国产成人亚洲精品| 国产精品乱码视频| 一区高清视频| 五月天亚洲综合情| 欧美精品一区免费| 国产精品亚洲αv天堂无码| 产国精品偷在线| 久久成人资源| 久久婷婷国产麻豆91天堂| 中文字幕精品在线播放| 91九色国产社区在线观看| 国产成人在线播放| 国产精品久久91| 少妇精品久久久久久久久久| 奇米一区二区三区四区久久| 国产在线欧美日韩| 久草精品电影| 综合色婷婷一区二区亚洲欧美国产 | 欧美老少配视频| 日韩wuma| 福利视频一区二区三区四区| 久久国产精品久久精品国产| 正在播放国产精品| 欧美激情第六页| 久久综合九色欧美狠狠| 美日韩精品免费视频| 热久久免费视频精品| 99在线影院| 国产精品久久久久久av| 日韩视频第二页| 国产欧美精品一区二区三区介绍 | 欧美精品在线播放| 欧美黄色免费影院| 国产富婆一区二区三区| 亚洲中文字幕无码中文字| 国产精品一区二区三区免费观看| 精品国产乱码一区二区三区四区| 精品无人乱码一区二区三区的优势| 国产精品久久国产三级国电话系列| 欧美h视频在线| 久久久久久18| 久久全国免费视频| 日本一区二区视频| 久99久在线| 欧美亚洲视频在线观看| 国产精品久久国产精品| 国产剧情日韩欧美| 国产精品对白一区二区三区| 青青青青草视频| 国产精品第1页| 国产成人综合亚洲| 欧美日韩亚洲一区二区三区四区| 久久成人人人人精品欧| 成人亚洲欧美一区二区三区| 午夜精品视频在线| 国产精品免费一区豆花| av观看久久| 成人av资源在线播放| 日本毛片在线免费观看| 麻豆国产va免费精品高清在线| www.亚洲一区二区| 免费国产a级片| 日韩经典在线视频| 亚洲综合视频一区| 国产精品日韩久久久久| 国产精品12| 风间由美一区二区三区| 欧美亚洲视频一区| 亚洲va久久久噜噜噜久久狠狠 | 午夜精品区一区二区三| 欧美精品免费在线观看| 久久精品aaaaaa毛片| 97精品视频在线观看| 国产欧美日韩精品丝袜高跟鞋| 日韩免费av在线| 欧美一区二区三区精美影视| 在线观看av的网址| 久久五月天色综合| 91九色在线观看视频| 国产欧亚日韩视频| 欧美无砖专区免费| 青青草影院在线观看| 日本一区二区三区四区五区六区| 欧美中日韩在线| 国产精品无码一本二本三本色| 国产成人一区二| 蜜桃传媒一区二区三区| 欧美一级欧美一级| 欧美一区二区.| 色噜噜狠狠一区二区三区| 五月天综合婷婷| 日本高清视频一区| 人妻av无码专区| 欧美精品免费观看二区| 黄色污污在线观看| 国产日韩欧美大片| 97成人在线观看视频| 久久人人爽人人| 国产成人在线视频| 国产精品视频内| 色综合久久88色综合天天看泰| 久久综合免费视频| 亚洲欧美日韩综合一区| 日韩欧美一级在线| 国内精品视频一区二区三区| 国产精品一区二区三区久久| 产国精品偷在线| 日韩亚洲欧美成人| 九九精品在线观看| 日韩欧美亚洲天堂| 国产有码在线一区二区视频| caoporn国产精品免费公开| 久久久国内精品| 久久久精品久久久| 亚洲一区三区在线观看| 欧美一区深夜视频| 成人9ⅰ免费影视网站| 久久激情视频久久| 性色av一区二区三区在线观看| 狠狠综合久久av| 国产成人激情小视频| 欧美情侣性视频| 日韩久久久久久久久久久久| 国产精品中文字幕在线| 日韩中文在线不卡| 午夜老司机精品| 国产欧美精品在线播放| 久久天堂av综合合色| 一区二区成人国产精品| 欧美日韩在线不卡一区| 国产高清在线一区二区| 亚洲图色在线| 国产精品自产拍高潮在线观看| 国产精品视频地址| 奇米成人av国产一区二区三区 | 久久本道综合色狠狠五月| 一区二区三区四区不卡| 国产在线久久久| 久久伊人精品天天| 国产日韩二区| 欧美一级淫片播放口| 黄色一级视频在线播放| 国产精品久久电影观看| 蜜桃在线一区二区三区精品| 久久综合伊人77777| 免费黄色福利视频| 欧美理论电影在线观看| 国产精品一区二区久久精品| 综合一区中文字幕| 国产精品18毛片一区二区| 国产成人亚洲综合91| 精品久久国产精品| 精品一区二区三区视频日产| 久久亚洲电影天堂| 成人精品久久一区二区三区| 午夜免费福利小电影| 99久久国产综合精品五月天喷水| 亚洲 欧美 综合 另类 中字| 久久久www免费人成黑人精品 | 成人av在线亚洲| 天堂资源在线亚洲视频| 久久久久久久免费| 欧美日韩亚洲一区二区三区四区| 精品国产一二三四区| 91精品国产自产91精品| 欧美一区二区视频在线播放| 欧美成人一二三| 国产成人亚洲综合无码| 精品一区二区三区免费毛片| 欧美激情视频给我| 国产av无码专区亚洲精品| 精品视频一区二区在线| 色狠狠久久av五月综合|| 国产精品免费一区二区| 久久人人97超碰人人澡爱香蕉| 欧美日韩亚洲一| 日韩av中文字幕第一页| 一区二区三区四区久久| 国产精品爽黄69| 久久久精彩视频| 阿v天堂2017|