• Tidak ada hasil yang ditemukan

Week 10 Assignment - Nptel

N/A
N/A
Protected

Academic year: 2024

Membagikan "Week 10 Assignment - Nptel"

Copied!
5
0
0

Teks penuh

(1)

X

NPTEL (https://swayam.gov.in/explorer?ncCode=NPTEL)

» An Introduction To Programming Through C++

(course)

Unit 12 - Week 10

(https://swayam.gov.in)

(https://swayam.gov.in/nc_details/NPTEL)

[email protected]

Announcements (announcements) About the Course (https://swayam.gov.in/nd1_noc20_cs53/preview) Ask a Question (forum) Progress (student/home) Mentor (student/mentor)

Course outline

How does an NPTEL online course work?

Week 0 Week 1 Week 2 Week 3 Week 4 Week 5 Week 6 Week 7 Week 8 Week 9

Week 10 Lecture 22 : Representing

Due on 2020-04-08, 23:59 IST.

1 point 1)

1 point 2)

Week 10 Assignment

The due date for submitting this assignment has passed.

As per our records you have not submitted this assignment.

Consider the following code fragment.

struct T{T* pt;};

T t;

t.pt = new T;

t.pt->pt = new T;

delete t.pt;

Which of the following are true?

The code contains a memory leak.

The variable t is allocated on the heap.

The code will produce a runtime error.

The variable *(t.pt) is allocated on the heap.

No, the answer is incorrect.

Score: 0

Accepted Answers:

The code contains a memory leak.

The variable *(t.pt) is allocated on the heap.

Consider the code below.

int main(){

int* x;

{ int y=5;

(2)

variable length entities: Part 1 : Introduction (unit?

unit=95&lesson=133) Lecture 22 :

Representing variable length entities: Part 2 : Heap memory basics (unit?

unit=95&lesson=134) Lecture 22 :

Representing variable length entities: Part 3 : Pitfalls of using heap memory (unit?

unit=95&lesson=135) Lecture 22 :

Representing variable length entities: Part 4 : Automating memory management (unit?

unit=95&lesson=136) Lecture 22 :

Representing variable length entities: Part 5 : Implementing a class with automated memory management 1 (unit?

unit=95&lesson=137) Lecture 22 :

Representing variable length entities: Part 6 : Implementing a class with automated memory management 2 (unit?

unit=95&lesson=138) Lecture 22 :

Representing variable length entities: Part 7 : Using the implemented class and conclusion

1 point 3)

4) x = &y;

}

{ int z = 10;}

cout<< *x;

}

Which of the following are true?

The code will give a compilation error.

The code has a dangling pointer.

The code has a memory leak.

The code will print 5.

No, the answer is incorrect.

Score: 0

Accepted Answers:

The code has a dangling pointer.

Consider the following code that uses the String class defined in the lecture.

String names[100];

char buffer[80];

cin >> buffer;

names[0] = buffer;

Which of the following is true?

The statement "names[0] = buffer;" will cause memory of size about 80 bytes to be allocated.

The statement "names[0] = buffer;" will cause memory about as large as the size of the typed name to be allocated.

The statement "names[0] = buffer;" will cause no memory allocation; all allocation will have happened when the statement "String names[100];" was executed.

The statement "names[0] = buffer;" will cause no memory to be allocated, names[i] will share memory already allocated for buffer.

No, the answer is incorrect.

Score: 0

Accepted Answers:

The statement "names[0] = buffer;" will cause memory about as large as the size of the typed name to be allocated.

In our String class, we implemented the + operator to mean concatenation. We might likewise define the product between a String s and an integer n to mean a String obtained by concatenating n copies of s.

Which member function would you define for this? Note that for implementing + we defined the member function operator+.

No, the answer is incorrect.

Score: 0

Accepted Answers:

(3)

(unit?

unit=95&lesson=139) Lecture 23 : The Standard Library: Part 1 : Class string (unit?

unit=95&lesson=140) Lecture 23 : The Standard Library: Part 2 : Class vector (unit?

unit=95&lesson=141) Lecture 23 : The Standard Library: Part 3 : Sorting vectors and arrays (unit?

unit=95&lesson=142) Lecture 23 : The Standard Library: Part 4 : Classes map and

unordered_map (unit?

unit=95&lesson=143) Lecture 23 : The Standard Library: Part 5 : Iterators (unit?

unit=95&lesson=144) Download

Videos (unit?

unit=95&lesson=186) Weekly

Feedback (unit?

unit=95&lesson=198) Quiz : Week 10 Assignment (assessment?

name=222) Week 10 Programming Assignment 1

(/noc20_cs53/progassignment?

name=223) Week 10 Programming Assignment 2

(/noc20_cs53/progassignment?

name=224) Week 10 Programming

1 point 5)

1 point 6)

1 point 1 point 7)

8)

1 point 9)

(Type: String) operator*

What would be the return type for this definition? Remember the return type for + was String.

No, the answer is incorrect.

Score: 0

Accepted Answers:

(Type: String) String

What would be the parameter type? Remember the parameter for + was const String&

No, the answer is incorrect.

Score: 0

Accepted Answers:

(Type: String) const int (Type: String) const int&

(Type: String) int (Type: String) int&

I have a file containing some words. The last word in the file is "*end*". I want to read the words and process them somehow. Which of the following will be most convenient to store the words?

two dimensional array of char.

SL (standard library) vector of array of char array of SL string.

SL vector of SL string No, the answer is incorrect.

Score: 0

Accepted Answers:

SL vector of SL string

What does the following code print?

string s = "abc";

s = s + s;

int i = s.find("bc");

i = s.find("bc",i+1) cout << i;

No, the answer is incorrect.

Score: 0

Accepted Answers:

(Type: Numeric) 4

What does the following code fragment print?

vector<int> v={1,2,3};

v.push_back(10);

v.push_back(15);

(4)

Week 11 Week 12 Text Transcripts

Assignment 3

(/noc20_cs53/progassignment?

name=227)

1 point 10)

1 point 11)

1 point 12)

1 point vector<int> w = v;

cout <<w.size();

No, the answer is incorrect.

Score: 0

Accepted Answers:

(Type: Numeric) 5

I wish to write a program in which I need to keep track of the children of different people. Suppose I call this data structure Children. For example I might use Children to record the information that Samudragupta had children Ramagupta and Chandragupta, and similarly for children of other persons.

Furthermore, assume that all persons are to be represented by their names, i.e. strings. Thus Children will be declared as

map<string,vector<string> > children;

How do I refer to the 0th child of "Vikramaditya" stored in children? Fill in the blanks without using any unnecessary characters.

No, the answer is incorrect.

Score: 0

Accepted Answers:

(Type: String) children["Vikramaditya"][0]

The statement below checks whether the children of "Samudragupta" are stored in Children, and if so, print the number of children.

if(blank1 > 0) cout << blank2 << endl;

What should blank1 be? Do not include unnecessary blanks.

No, the answer is incorrect.

Score: 0

Accepted Answers:

(Type: String) children.count("Samudragupta")

What should blank2 be? Do not include unnecessary blanks.

No, the answer is incorrect.

Score: 0

Accepted Answers:

(Type: String) children["Samudragupta"].size()

(5)

Referensi

Dokumen terkait

Score: 0 Accepted Answers: The space between realism and realism accepted by humans Latency in Tracking the head generally causes Sickness Discomfort Fatigue All the above No, the

Score: 0 Accepted Answers: Extended range of slug flow When different flow patterns occur along a microchannel, The flow pattern observed at the exit is designated as the prevailing

Score: 0 Accepted Answers: i sparsity of effects principle, projection property, sequential experimentation When we estimate A, B, and C with complementary one-half fraction, we are

Score: 0 Accepted Answers: mi- In 8-10 Identify the correct primary stress for following words: Demoralize /dɪˈmɒrəlʌɪz/ /ꞌdɪmɒrəlʌɪz/ /dɪmɒrəꞌlʌɪz/ /dɪmɒꞌrəlʌɪz/ No, the

Score: 0 Accepted Answers: Prior to the external loading, micro-cracks are not present in hydrated cement paste of the concrete Identify the TRUE statement with regard to the modulus

Score: 0 Accepted Answers: Pressure In carbon microphones, a variation in which of the following parameter was correlated to find out sound pressure level SPL?.

Score: 0 Accepted Answers: The probability of acceptance at acceptable quality level AQL is same as that at rejection quality level RQL Larson Nomogram is based on Binomial

Score: 0 Accepted Answers: Deep Blue As discussed in the “Artificial Intelligence: Search Methods for Problem Solving - Prologue”, this course is about Problem solving Model Based