Computer Programming

Similar documents
Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

Computer Programming

cout << "How many numbers would you like to type? "; cin >> memsize; p = new int[memsize];

Computer Programming

CS 101 Computer Programming and utilization. Dr Deepak B Phatak Subrao Nilekani Chair Professor Department of CSE, Kanwal Rekhi Building IIT Bombay

Review: C++ Basic Concepts. Dr. Yingwu Zhu

Linked List using a Sentinel

Kapil Sehgal PGT Computer. Science Ankleshwar Gujarat

Computer Programming

Encapsulation in C++

CMSC 341 Lecture 7 Lists

Data Structures and Algorithms

CS250 Final Review Questions

Polymorphism. Zimmer CSCI 330

l Determine if a number is odd or even l Determine if a number/character is in a range - 1 to 10 (inclusive) - between a and z (inclusive)

Ch. 17: Linked Lists. Introduction to Linked Lists

CIS 190: C/C++ Programming. Classes in C++

CS 115 Midterm 2 Review Quiz

CS250 Final Review Questions

Classes. Logical method to organise data and functions in a same structure. Also known as abstract data type (ADT).

Dot and Scope Resolution Operator

1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol.

Introduction to Classes

CS250 Final Review Questions

CMPT 117: Tutorial 1. Craig Thompson. 12 January 2009

CSCI 102L - Data Structures Midterm Exam #1 Fall 2011

Chapter 4. Defining Classes I

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

Comp 11 - Summer Session Hashmap

Chapter 6 Structures and Classes. GEDB030 Computer Programming for Engineers Fall 2017 Euiseong Seo

Computer Programming

C++ Final Exam 2017/2018

Recap of OO concepts. Objects, classes, methods and more. Mairead Meagher Dr. Siobhán Drohan. Produced by:

PROGRAMMING IN C++ KAUSIK DATTA 18-Oct-2017

Add Subtract Multiply Divide

Short Notes of CS201

Topics. Constructor. Constructors

Non-numeric types, boolean types, arithmetic. operators. Comp Sci 1570 Introduction to C++ Non-numeric types. const. Reserved words.

Name Section: M/W or T/TH. True or False (14 Points)

CS201 - Introduction to Programming Glossary By

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

Come and join us at WebLyceum

Jordan University of Science & Technology Department of Computer Science CS 211 Exam #1 (23/10/2010) -- Form A

Arrays in C++ Instructor: Andy Abreu

CLASSES AND OBJECTS IN JAVA

C++ Programming: Polymorphism

COMP 11 Class 17 Outline

2 2

Name SECTION: 12:45 2:20. True or False (12 Points)

Chapter 13: Introduction to Classes Procedural and Object-Oriented Programming

Pointer Data Type and Pointer Variables

CS 101 Computer Programming and utilization. Dr Deepak B Phatak Subrao Nilekani Chair Professor Department of CSE, Kanwal Rekhi Building IIT Bombay

Friend Functions and Friend Classes

CSC1322 Object-Oriented Programming Concepts

Lecture 7. Log into Linux New documents posted to course webpage

EINDHOVEN UNIVERSITY OF TECHNOLOGY Department of Mathematics and Computer Science

! A data structure representing a list. ! A series of nodes chained together in sequence. ! A separate pointer (the head) points to the first

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

EL2310 Scientific Programming

Constants, References

! Determine if a number is odd or even. ! Determine if a number/character is in a range. - 1 to 10 (inclusive) - between a and z (inclusive)

CS 11 C++ track: lecture 1

CSE115 Introduction to Computer Science I Coding Exercise #7 Retrospective Fall 2017

Use the template below and fill in the areas in Red to complete it.

CPE 112 Spring 2015 Exam III (100 pts) April 8, True or False (12 Points)

CS11 Introduction to C++ Fall Lecture 1

Common Misunderstandings from Exam 1 Material

Comp 248 Introduction to Programming Chapter 4 - Defining Classes Part A

Lab 12 Object Oriented Programming Dr. John Abraham

University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ June Exam

CS32 - Week 2. Umut Oztok. July 1, Umut Oztok CS32 - Week 2

FORM 2 (Please put your name and form # on the scantron!!!!)

CS11 Intro C++ Spring 2018 Lecture 1

MIDTERM REVIEW. midterminformation.htm

LAB 4.1 Relational Operators and the if Statement

FORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each):

5. Assuming gooddata is a Boolean variable, the following two tests are logically equivalent. if (gooddata == false) if (!

Abstract Data Types (ADTs) 1. Legal Values. Client Code for Rational ADT. ADT Design. CS 247: Software Engineering Principles

Week 2. Relational Operators. Block or compound statement. if/else. Branching & Looping. Gaddis: Chapters 4 & 5. CS 5301 Spring 2018.

Transcription:

Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering Session: Quiz and Practice Questions on Classes Part 1 Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, 1

Recap Quiz Q1. A private member function of a structure can be invoked from (A) Another member function of the same structure (B) A member function of another structure (C) Any ordinary (non-member) function in the program (D) The main function in the program 2 Dr. Deepak B. Phatak & Dr. Supratik Chakraborty,

Recap Quiz Q2. Consider the class definition class CL { private: int a; void f1() { }; public: int b; void f2() { }; }; Which of the following is/are true of class CL? A. a and b can be used in the body of f2 B. b but not a can be used in the body of f2 C. a cannot be used in the body of f1 D. b cannot be used in the body of f1 3 Dr. Deepak B. Phatak & Dr. Supratik Chakraborty,

Recap Quiz Q3. By default, everything in a struct is assumed to be B1 and everything in a class is assumed to be B2. A. B1: private, B2: public B. B1: private, B2: private C. B1: public, B2: private D. B1: public, B2: public 4 Dr. Deepak B. Phatak & Dr. Supratik Chakraborty,

Recap Quiz Q4. Accessor and mutator functions can be used to A. Read and write only private data members B. Read and write any data member C. Hide internal representation details of data members D. Expose internal representation details of data members 5 Dr. Deepak B. Phatak & Dr. Supratik Chakraborty,

Recap Quiz Q5. A class CL has 3 constructor functions. Which of the following must be true? A. The constructor functions must have different names B. The constructor functions must have different return types C. The constructor functions must have different lists of parameter types D. All of the above 6 Dr. Deepak B. Phatak & Dr. Supratik Chakraborty,

Practice Question 1 We studied about directed graphs in last class. 1 2 4 5 3 7 Dr. Deepak B. Phatak & Dr. Supratik Chakraborty,

Practice Question 1 (Recap from last class) Nodes must be represented using a structure struct mynode { }; Assume all nodes in the graph are stored in an array named nodes. Id of a node is its index in the array. Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, 8

Practice Question 1A We will use the following structure to represent a node struct LinkedNodes { struct mynode { int nodeid; int id; LinkedNodes *next; LinkedNodes *outgoing; } LinkedNodes *incoming; } Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, 9

Practice Question 1 We now want each node and each edge to have a weight (of type float) 1 2.1 3.1 4.2 2 4.1 2.3 3.0 0.1 4 5 9.3 1.1 1.1 3 3.9 2.5 Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, 10

Practice Question 1 (Recap from last class) Modify the mynode and LinkedNodes structure definitions (define these to be classes) to be able to represent directed graphs with weighted nodes and edges Ensure that the weight of a node cannot be accessed directly from the main program, and similarly for the weight of an edge, its incoming and outgoing edges. Feel free to add appropriate member functions with appropriate access control Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, 11

Practice Question 1A int main () { int numnodes; cout << Give no. of nodes: ; cin >> numnodes; mynode *nodes = new mynode[numnodes]; if (nodes == NULL) { cout << Memory allocation failure. << endl; return -1; } else { newinitnodes(nodes, numnodes); } (continued on next slide ) Can ask for weights of nodes Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, 12

Practice Question 1A int startedge, endedge; float edgewt; while (true) { // Reading in edges, one at a time cout << Give start of edge (-1 to quit): ; cin >> startedge; if (startedge == -1) break; cout << Give end of edge (-1 to quit): ; cin >> endedge; if (endedge == -1) break; cout << Weight of edge: ; cin >> edgewt; newaddedge(nodes, startedge, endedge, edgewt); } (continued on next slide ) Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, 13

Practice Question 1A // Printing adjacent nodes of every node for (int i = 0; i < numnodes; i++) { cout << Metric for node << i << : // Metric (sum of in edge wts sum of out edge wts) // node wt nodes[i].printmetric(); } return 0; } Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, 14

Practice Question 1A Write the functions void newinitnodes(mynodes *nodes, int numnodes); void newaddedge (mynodes *nodes, int start, int end, float wt); void printmetric(); Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, 15