For 10 possible values of N, values of a, b, and c will be as under

Size: px
Start display at page:

Download "For 10 possible values of N, values of a, b, and c will be as under"

Transcription

1 CS101 Mid-semester examination Autumn Questions with sample answers Q. 1. The following program is executed with input formed by the last two digits of your Roll number, (if Roll no. is 11D50038, input is 38). Write the exact output. (4) int main(){ int R, N, k, m, a, b, c, A[10]; cin >> R; N = (R/10 + R%10) % 10; If (N == 0) { N = 10; cout << Value of N is: << N << endl; a = 0; for (k =1; k<=n; a+=k, k++); cout << a is: << a << endl; b = 1; m = 1; while (m < N/2){ b = b * m; m++; cout << b is: << b << endl; m = 1; k =0; do { if (m%n == 0){ A[k] = m; k ++; m ++; while (k <10); c = A[2]; cout << c is: << c << endl; Ans. 1. First find N, by adding the last two digits of the roll number, and then calculating modulo 10 remainder of that sum. If N = 0, reset it to 10. For 10 possible values of N, values of a, b, and c will be as under N a b c

2 Q. 2. A polynomial in x, of degree N, has been represented by storing its N +1 coefficients in an array A[50]. Its value for any x is given by A[N] + A[N-1] x + A[N-2] x 2 + A[N-3] x A[0] x N This polynomial needs to be evaluated for different values of x at different points in a program. Write a C++ function to calculate its value for any given x. (3) Ans. 2. This problem is similar to the one discussed in the class on evaluation of polynomial functions whose coefficients are stored in an array. The problem considered then was to evaluate: A[0] + A[1] x + A[2] x 2 + A[3] x A[N] x N The difference is the oder in which these coefficients appear in this question. The C++ function can be written as /* Q2 Midsem 2011 */ float poly(float A[50], int N, float x){ float sum, term;int k; sum = 0.0, term =1.0; for (k = N; k >=0; k--){ sum = sum + A[k] * term; term = term*x; return sum; 2

3 Q. 3. A value of x is given, such that 0 < x < 1. We need to find the sum of terms of the following series, such that all terms greater than 1.0E-12, are included in the sum. Write a program to read x, verify that it is within given limits, and find the desired sum. The program should also print the number of terms added in the sum. (3) sum = 1 + x + x*x + x*x*x + x* x*x*x +.. Ans. 3. /* Q3 Midsem 2011*/ #include <iostream> #include <cstring> using namespace std; int main() { float x, sum, term; int N; cout << "Give value of x" << endl; cin >> x; if ((x <= 0.0) (x >= 1.0)) { cout << "Invalid value: " << x << endl; return 1; N=0; term = 1.0; sum = 0.0; while (term > 1.0E-12){ sum = sum + term; term = term * x; N++; cout << "Sum is: " << sum << endl; cout << "No of terms added: " << N << endl; return 0; 3

4 Q. 4. An n-gram is a sub-sequence of n successive items from a given sequence, say, all characters in a word. For example, following n-grams can be formed from the word host : 1-gram: h, o, s, t (4 words of 1 character each) 2-gram: ho, os, st (3 words of 2 characters each) 3-gram: hos, ost (2 words of 3 characters each) 4-gram: host (1 word of 4 characters This is the original word) Write a program to print all the n-grams found for a given word with N characters. Compare the count of all n-grams with (N*N +N)/2, which is the actual theoretical value. (6) Ans. 4. /* Q4 Midsem 2011 */ #include<iostream> #include<cstring> using namespace std; int main(){ int k,m, j, wordlength, count=0; char word[80], ngram[50][80]; cout<<"enter a word : "; cin >> word; wordlength=strlen(word); /************************************** finding, counting and printing n-grams **************************************/ count = 0; for (k = 1; k <= wordlength; k++){ /* find all k-grams */ cout << endl << k <<"-grams: "; for (m = 0; m < wordlength -k+1; m++){ for (j =0; j < k; j++){ cout << word[m+j]; cout << ", "; count ++; cout << endl << "count is : " << count << endl; if (count == (wordlength*wordlength +wordlength)/2){ cout <<"tallies with theoretical value" << endl; else cout << "incorrect count" << endl; return 0; 4

5 Q. 5. Two arrays A[100] and B[100], contain M and N integer numbers respectively. Each array has been sorted in ascending order. Write a program to merge the contents of these two arrays into another integer array C[200], such that this resulting array is sorted in descending order. For example, if A contains 5, 7, 15; and B contains 3, 4, 13, 14, 17; then the resulting merged array C should contain 17, 15, 14, 13, 7, 5, 4, 3. Note: All legal values of integer type could be present in the array. As such, any artificial sentinel value cannot be inserted in the arrays, for use in your merge algorithm. (6) Ans. 5. This is another problem similar to one discussed in the class. There are two differences. The first is the stipulation that you cannot use any artificial sentinel value. The second is that the resultant array C[] needs to be sorted in the opposite (descending) order as compared to the order in which arrays A[] and B[] are sorted. To address the first issue, we need to tweak the merge algorithm a bit. When we reach the end of any one array, one approach is to directly copy the remaining elements of the other array into the result C[]. The second issue can be addressed in one of the two ways. The first is to start the merging process backwards. The other is to perform a regular merge in C[], getting it in ascending order, and then sort it again in descending order. The second approach, apart from requiring extra programming work, results in a much costlier operation, as it involves the sorting of the entire result. We must remember the basic objective behind a merge operation. To recapitulate, if we have to sort a large array containing N elements, the algorithm we have studied so far requires order of N 2 operations. Since the merge operation requires only an order of N operations, we want to divide the original array in two parts, each requiring only an order of (N/2) 2 operations, followed by a merge. We thus get a considerable saving in overall execution time of the entire operation. The question should be understood in this context, namely, that the two arrays A[] and B[] probably came out of a single larger array as a result of such subdivision. Re-sorting the merged array C[], essentially puts us back to square one, in that, it amounts to sorting the entire original larger array. In fact it is worse, since we would spend additional time in sorting the two sub-arrays A[] and B[]. The sample program given here merges the two arrays in reverse direction. A special mention must be made of the shorter programs which can be written using the power of the post increment/decrement operators of C++. Such usage often reduces multiple statements into a single one, thus avoiding the necessity to use pair of curly brackets to put these multiple statements together withing a 'while' or 'if' statement. For example, the two constructs given below are identical in their semantics. Version (1): if (A[i] < B[j]){ C[k]=B[j]; k = k+1; j = j-1; else { C[k]=A[i]; k = k+1; i =i-1; Version 2 if (A[i] < B[j])C[k++]=B[j--]; else C[k++]=A[i--]; 5

6 /* Q5 Midsem 2011 */ /* Based on a program written by Firuza Aibara Values that are accepted in ascending order, are stored in arrays A B. The resultant array "C" Is formed using merge algorithm, which is performed in reverse order as desired. */ #include<iostream> using namespace std; int main(){ int A[100], B[100], C[200], M, N, total; int i, j, k; // Read arrays A[] and B[] cout<<"\nenter number of elements in array A : "; cin>>m; cout<<"enter number of elements in array B : "; cin>>n; total=m+n; cout<<"\nenter "<<M<<" values for Array A in ascending order \n"; for(i=0;i<m;i++)cin>>a[i]; cout<<"\nenter "<<N<<" values for Array B in ascending order \n"; for(i=0;i<n;i++)cin>>b[i]; cout<<"\nvalues in Array A :-\n"; for(i=0;i<m;i++) cout<<a[i]<<" "; cout << "\n"; cout<<"\nvalues in Array B :-\n"; for(i=0;i<n;i++)cout<<b[i]<<" "; cout<<"\n"; // Merging array A and B in Descending order i=m-1; j=n-1; k =0; while (k < total){ if (A[i] < B[j])C[k++]=B[j--]; else C[k++]=A[i--]; if (i == 0){ // reached end of A, copy B to C while (j > 0) C[k++] = B[j--]; if (j == 0){ // reached end of B, copy A to C while (i > 0) C[k++] = A[i--]; cout<<"resultant Array C in Descending order :-\n"; for(i=0;i<total;i++)cout<<c[i]<<" "; cout<<"\n"; return 0; 6

7 Problem (for questions 6, 7, and 8). A branch of a bank has N customers (N < 50000). A customer maintains one or more accounts in that branch. Each customer has a customer-id which is a six digit unique customer number starting with 1. A 7-digit account-number is allotted for each account held by a customer. Every account number starts with 411 for that branch. Balance amount in each account is known. It is required to find out who holds maximum amount in that branch. For finding this maximum amount held by any customer, the sum of balances in all the accounts of each customer is to be considered. The data of all customers is given such that there are three entries in one line, separated by one or more blanks, containing the customer-id, account-number, and balance; and there are as many lines as there are accounts in that branch. An extra line is typed as input in the end, containing 0 for all the three values. Some sample entries are given below: (Another account for same customer , as in line 3 ) (last line containing artificial data) Write a program to successively answer the following questions. In your program, clearly mark the beginning of the portion corresponding to each question, by a comment line. Q. 6. Define 3 arrays custid[], acctno[], and balance[], to hold data for all possible accounts in that branch. Read input from each line appropriately into these arrays. There is no need to use any files, as the normal cin statement reading three values at a time, is adequate. Verify that the customer-id and account-number are valid as per prescribed rules. For any invalid value, terminate the program. Stop reading input, when you reach the last line containing artificial data (all 0 values). Count the total number of accounts, in an integer variable Nacct. (3) Q. 7. Assume that Q6 has been correctly solved. Now, compute the total balance for each customer, by adding the balance amounts in all the accounts held by that customer. Also count the number of accounts held by each customer. Define three new arrays ucustid[], totbalance[], and numacct[]. For each customer, create only one entry in each of these three arrays. For example, the entries in these arrays, for customers and will be: ucustid totbalance numacct (This customer has only one account) (The customer has two accounts, the total balance calculated) Hint: Consider sorting the original arrays so that the entries with same customer-id come as consecutive elements of array custid[]. (5) Q.8. Assume that Q7 has been correctly answered. Now, find and print the maximum balance amongst all the totbalance[] entries. Then, for each customer having this maximum balance, print the cutomer-id, account-number, and balance, for every account number belonging to that customer. (5) Ans. 6. and 7. and 8. Q. 6 is straight forward. It simply involves reading the data, and 7

8 validating that the customer-ids and the account-numbers start with '1'. and '411' respectively. The problem requires you to terminate the program if there is any invalid record. This would never be done in real life. Otherwise, you would correct the invalid record and repeat the execution, only to find another invalid input somewhere later. This could be very time consuming if you indeed have about accounts in the branch. In actual practice, the input data would always be entered into a file. The validation program would be run on this file to find all erroneous records, which are put in a separate file. The correct records are normally processed, or are stored in another file. The algorithm for question 7 is partially explained in the question itself, through the hint to sort all input records on customer id. Records for the same customer will now be in consecutive array locations. By scanning the array, we can easily assemble total balance for each customer by adding balances from consecutive records for that customer. Question 8 requires you to first fine the maximum balance of the entire lot, by using the new arrays. Now you can scan the new ucustid[] array for a customer whose balance matches the maximum, find the unique customer-id, and then search for it in the original account arrays, printing each one as you find it. The following program does the composite job for all the three questions. Some useful comments have been added for better understaning. /* Q6,7,8 midsem 2011*/ #include <iostream> using namespace std; int main() { /* Q */ int custid[50000], acctno[50000]; float balance[50000]; int k, Nacct; k = 0; Nacct =0; cin >> custid[k] >> acctno[k] >> balance[k]; cout << custid[k] << acctno[k] << balance[k]; cout << endl; while (custid[k]!=0 ){ /* received a proper entry, validate data */ if ((custid[k]/100000!= 1) (acctno[k]/10000!=411)){ cout << "invalid data" << endl; cout <<custid[k]<< " "<<acctno[k]<<" " << balance[k]; cout << endl; return 1; cout<<custid[k]<<" "<< acctno[k]<< " "<<balance[k]<<endl; Nacct++; k++; cin >> custid[k] >> acctno[k] >> balance[k]; cout <<"Total account entries are: " << Nacct << endl; 8

9 /* Q */ /* first sort data on custid */ int tempid, tempac; float tempbal; int mincustid, pos, i, j; for (i= 0; i < Nacct; i++){ mincustid = custid[i]; // assume ith element to be smallest pos =i; for (j = i+1; j <Nacct; j++){ if (custid[j] < mincustid){ pos = j; mincustid = custid[j]; tempid =custid[pos]; custid[pos]=custid[i]; custid[i]=tempid; tempac =acctno[pos]; acctno[pos]=acctno[i]; acctno[i]=tempac; tempbal=balance[pos];balance[pos]=balance[i];balance[i]=tempbal; cout << i<< " "<< custid[i]<<" "<<acctno[i]<<" "<<balance[i]; cout<< endl; /* now calculate total balance for each unique customer*/ int ucustid[50000], numacct[50000]; float totbalance[50000]; int numucust; // number of unique customers k = 0; // index for the new arrays ucustid[0] = custid[0]; numacct[0] = 1; totbalance[0] = balance[0]; // 0th entry captured as new customer for (i =1; i < Nacct; i++){ // scan all accounts if (custid[i]!= ucustid[k]){ // found new unique customer k++; ucustid[k] = custid[i]; numacct[k] = 1; totbalance[k] = balance[i]; else { numacct[k]++; totbalance[k] += balance[i]; // same customer, continue to accumulate balance numucust = k+1; // Total number of unique customers cout << endl << "Total balances" << endl; for(i=0; i<numucust; i++){ cout << i <<" " <<ucustid[i]<<" "<<numacct[i]<<" "; cout << totbalance[i] << endl; 9

10 /* Q */ /* First find the maximum balance */ float maxbalance; maxbalance = totbalance[0]; for (i=0; i < numucust; i++){ if(maxbalance < totbalance[i]) maxbalance = totbalance[i]; cout << " Maximum balance is: "<< maxbalance << endl<<endl<<endl; /* Now scan the uniqu customers for this max balance */ k=0; cout << " Customers with Maximum Balance:" << endl<<endl; for(i=0; i<numucust; i++){ if (totbalance[i]!= maxbalance) continue; k++; // else, we have found a new customer with maxbalance cout << k << ". " << "customer "<<ucustid[i]; cout << " has following account(s)" << endl; int sno = 0; for (j =0; j<nacct; j++){ //scan the accounts array if(ucustid[i] == custid[j]){ // found an account sno++; cout << " "<<sno <<" "<< acctno[j] << " "; cout << balance[j] << endl; return 0; Sample input file 'accountdata.txt'

11 Q. 9. A monochrome image of size H (Height) by W (Width) was captured in poor light. As a result, all the pixel values are known to be 130 or less. Due to some problem in the camera, rectangular white patches have got superimposed on the picture. The values of all pixels in such patches are 255. It is guaranteed that every patch is exactly rectangular. Write a program to read values of H, and W; and then values of individual pixels in an array pic[300][500]. Then find out the total number of pixels in the largest white patch (patch with largest area) present in the image. Print the start-row, start-column, and end- row, end-column of this patch. If there are multiple patches with the same size, you may print these values for any one of these patches. Two sample patches are shown in the following sketch. (5) Ans. 9. You will recall the discussions in the class on the way digital images are handled. In particular, we had seen a program which performs histogram equalization on a monochrome image. That program essentially dealt with computations involving the statistical properties of the pixel values in the image. This problem deals with the geometric placement of the pixels in a twodimensional lay-out. This question is a relatively simple version of problems of image processing involving edge detection. Since the white patches are defined to be 'rectangular', you just have to scan rows to find if any consecutive white pixels exist, and if these do exist, to find in how many subsequent columns these patches continue further. You can track the row number; and the start and end column number of each patch as you encounter it first. Additionally, keep counting the total number of pixels. Start with maxsize of 0, and maintain separately, the details of the patch with current max size. This and the Q10 will be discussed briefly in a lecture later. A problem often faced is to input large values of pixels while testing such programs. We will later see how such data can be read from a real image. But we do need large test-data with predictable behaviour to test many of our algorithms. What is included here is a program which generates artificial data for a monochrome image in a file 'picdata.txt'. It collects the coordinates of desired number of white patches from you, and replaces the corresponding pixels with value 255. Study this program to revise your understanding of simple file operations. We will be discussing more on file processing next week. 11

12 /* Creating artificial data for a monochrome image to support testing of solutions to Q9 */ #include <iostream> using namespace std; int main() { int pic[500][300]; int H, W, i,j, k, N, m, n; /* Fill up picture with artificial data*/ H =20; W = 20; for(i=0;i<h;i++) for(j=0;j<w;j++)pic[i][j]=i; /* insert white patches */ int xl[10],yl[10],xr[10],yr[10],npatches; //x, y coordiantes of uperleft and lower right corners of pathces cout << "Give number of patches"<<endl; cin >> npatches; for (i =0; i<npatches;i++){ cout << "Give x,y cordinates of top left, bottom right corner"; cin >> xl[i] >> yl[i] >> xr[i] >> yr[i]; for(k=xl[i]; k<=xr[i]; k++){ for(m=yl[i]; m<= yr[i]; m++){ pic[k][m] = 255; cout << endl; FILE* fp; fp = fopen("picdata.txt", "w"); fprintf(fp, "%d %d \n", H, W); for(i=0;i<h;i++){ for(j=0;j<w;j++){ fprintf(fp, "%d ", pic[i][j]); fprintf(fp, "\n"); fclose (fp); /* picture Data file created */ return 0; 12

CS302 Midterm Exam Answers & Grading James S. Plank September 30, 2010

CS302 Midterm Exam Answers & Grading James S. Plank September 30, 2010 CS302 Midterm Exam Answers & Grading James S. Plank September 30, 2010 Question 1 Part 1, Program A: This program reads integers on standard input and stops when it encounters EOF or a non-integer. It

More information

Increment and the While. Class 15

Increment and the While. Class 15 Increment and the While Class 15 Increment and Decrement Operators Increment and Decrement Increase or decrease a value by one, respectively. the most common operation in all of programming is to increment

More information

Computer Programming

Computer Programming Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering Session: Character Strings Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, 1 Quick Recap

More information

Today in CS161. Lecture #7. Learn about. Rewrite our First Program. Create new Graphics Demos. If and else statements. Using if and else statements

Today in CS161. Lecture #7. Learn about. Rewrite our First Program. Create new Graphics Demos. If and else statements. Using if and else statements Today in CS161 Lecture #7 Learn about If and else statements Rewrite our First Program Using if and else statements Create new Graphics Demos Using if and else statements CS161 Lecture #7 1 Selective Execution

More information

2. ARRAYS What is an Array? index number subscrip 2. Write array declarations for the following: 3. What is array initialization?

2. ARRAYS What is an Array? index number subscrip 2. Write array declarations for the following: 3. What is array initialization? 1 2. ARRAYS 1. What is an Array? Arrays are used to store a set of values of the same type under a single variable name. It is a collection of same type elements placed in contiguous memory locations.

More information

CS222 Homework 4(Solution)

CS222 Homework 4(Solution) CS222 Homework 4(Solution) Dynamic Programming Exercises for Algorithm Design and Analysis by Li Jiang, 2018 Autumn Semester 1. Given an m n matrix of integers, you are to write a program that computes

More information

CSCE Practice Midterm. Data Types

CSCE Practice Midterm. Data Types CSCE 2004 - Practice Midterm This midterm exam was given in class several years ago. Work each of the following questions on your own. Once you are done, check your answers. For any questions whose answers

More information

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

CS 101 Computer Programming and utilization. Dr Deepak B Phatak Subrao Nilekani Chair Professor Department of CSE, Kanwal Rekhi Building IIT Bombay CS 101 Computer Programming and utilization Dr Deepak B Phatak Subrao Nilekani Chair Professor Department of CSE, Kanwal Rekhi Building Bombay Lecture 4, Conditional execution of instructions Friday, August

More information

SECOND JUNIOR BALKAN OLYMPIAD IN INFORMATICS

SECOND JUNIOR BALKAN OLYMPIAD IN INFORMATICS SECOND JUNIOR BALKAN OLYMPIAD IN INFORMATICS July 8 13, 2008 Shumen, Bulgaria TASKS AND SOLUTIONS Day 1 Task 1. TOWERS OF COINS Statement Asen and Boyan are playing the following game. They choose two

More information

Describing and Implementing Algorithms

Describing and Implementing Algorithms Describing and Implementing Algorithms ECE2036 Lecture 1 ECE2036 Describing and Implementing Algorithms Spring 2016 1 / 19 What is an Algorithm? According to Wikipedia: An algorithm is a sequence of instructions,

More information

Review of Important Topics in CS1600. Functions Arrays C-strings

Review of Important Topics in CS1600. Functions Arrays C-strings Review of Important Topics in CS1600 Functions Arrays C-strings Array Basics Arrays An array is used to process a collection of data of the same type Examples: A list of names A list of temperatures Why

More information

Solving a 2D Maze. const int WIDTH = 10; const int HEIGHT = 10;

Solving a 2D Maze. const int WIDTH = 10; const int HEIGHT = 10; Solving a 2D Maze Let s use a 2D array to represent a maze. Let s start with a 10x10 array of char. The array of char can hold either X for a wall, for a blank, and E for the exit. Initially we can hard-code

More information

1) What of the following sets of values for A, B, C, and D would cause the string "one" to be printed?

1) What of the following sets of values for A, B, C, and D would cause the string one to be printed? Instructions: This homework assignment focuses primarily on some of the basic syntax and semantics of C++. The answers to the following questions can be determined from Chapters 6 and 7 of the lecture

More information

CAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE

CAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE CAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE a) Mention any 4 characteristic of the object car. Ans name, colour, model number, engine state, power b) What

More information

Week 3. Function Definitions. Example: Function. Function Call, Return Statement. Functions & Arrays. Gaddis: Chapters 6 and 7.

Week 3. Function Definitions. Example: Function. Function Call, Return Statement. Functions & Arrays. Gaddis: Chapters 6 and 7. Week 3 Functions & Arrays Gaddis: Chapters 6 and 7 CS 5301 Fall 2015 Jill Seaman 1 Function Definitions! Function definition pattern: datatype identifier (parameter1, parameter2,...) { statements... Where

More information

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible) Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program

More information

CS 240 Computer Programming 1 Arrays

CS 240 Computer Programming 1 Arrays CS 240 Computer Programming 1 Arrays 1 2 #1 Choose the correct answer.. 3 #1 1.Which of the following correctly declares an array? Answer A. int anarray[10]; B. int anarray; C. anarray{10}; D. array anarray[10];

More information

o Counter and sentinel controlled loops o Formatting output o Type casting o Top-down, stepwise refinement

o Counter and sentinel controlled loops o Formatting output o Type casting o Top-down, stepwise refinement Last Time Let s all Repeat Together 10/3/05 CS150 Introduction to Computer Science 1 1 We covered o Counter and sentinel controlled loops o Formatting output Today we will o Type casting o Top-down, stepwise

More information

REPETITION CONTROL STRUCTURE LOGO

REPETITION CONTROL STRUCTURE LOGO CSC 128: FUNDAMENTALS OF COMPUTER PROBLEM SOLVING REPETITION CONTROL STRUCTURE 1 Contents 1 Introduction 2 for loop 3 while loop 4 do while loop 2 Introduction It is used when a statement or a block of

More information

INTRODUCTION TO PROGRAMMING

INTRODUCTION TO PROGRAMMING FIRST SEMESTER INTRODUCTION TO PROGRAMMING COMPUTER SIMULATION LAB DEPARTMENT OF ELECTRICAL ENGINEERING Prepared By: Checked By: Approved By Engr. Najeeb Saif Engr. M.Nasim Kha Dr.Noman Jafri Lecturer

More information

A SHORT COURSE ON C++

A SHORT COURSE ON C++ Introduction to A SHORT COURSE ON School of Mathematics Semester 1 2008 Introduction to OUTLINE 1 INTRODUCTION TO 2 FLOW CONTROL AND FUNCTIONS If Else Looping Functions Cmath Library Prototyping Introduction

More information

Week 3. Function Definitions. Example: Function. Function Call, Return Statement. Functions & Arrays. Gaddis: Chapters 6 and 7. CS 5301 Spring 2018

Week 3. Function Definitions. Example: Function. Function Call, Return Statement. Functions & Arrays. Gaddis: Chapters 6 and 7. CS 5301 Spring 2018 Week 3 Functions & Arrays Gaddis: Chapters 6 and 7 CS 5301 Spring 2018 Jill Seaman 1 Function Definitions l Function definition pattern: datatype identifier (parameter1, parameter2,...) { statements...

More information

Introduction to Arrays

Introduction to Arrays Introduction to Arrays One Dimensional Array. Two Dimensional Array. Inserting Elements in Array. Reading Elements from an Array. Searching in Array. Sorting of an Array. Merging of 2 Arrays. What is an

More information

Reading from and Writing to Files. Files (3.12) Steps to Using Files. Section 3.12 & 13.1 & Data stored in variables is temporary

Reading from and Writing to Files. Files (3.12) Steps to Using Files. Section 3.12 & 13.1 & Data stored in variables is temporary Reading from and Writing to Files Section 3.12 & 13.1 & 13.5 11/3/08 CS150 Introduction to Computer Science 1 1 Files (3.12) Data stored in variables is temporary We will learn how to write programs that

More information

BITG 1113: Array (Part 1) LECTURE 8

BITG 1113: Array (Part 1) LECTURE 8 BITG 1113: Array (Part 1) LECTURE 8 1 1 LEARNING OUTCOMES At the end of this lecture, you should be able to: 1. Describe the fundamentals of arrays 2. Describe the types of array: One Dimensional (1 D)

More information

CSCE Practice Midterm. Data Types

CSCE Practice Midterm. Data Types CSCE 2004 - Practice Midterm This midterm exam was given in class several years ago. Work each of the following questions on your own. Once you are done, check your answers. For any questions whose answers

More information

BITG 1233: Array (Part 1) LECTURE 8 (Sem 2, 17/18)

BITG 1233: Array (Part 1) LECTURE 8 (Sem 2, 17/18) BITG 1233: Array (Part 1) LECTURE 8 (Sem 2, 17/18) 1 LEARNING OUTCOMES At the end of this lecture, you should be able to: 1. Describe the fundamentals of arrays 2. Describe the types of array: One Dimensional

More information

CMPE110 - EXPERIMENT 1 * MICROSOFT VISUAL STUDIO AND C++ PROGRAMMING

CMPE110 - EXPERIMENT 1 * MICROSOFT VISUAL STUDIO AND C++ PROGRAMMING CMPE110 - EXPERIMENT 1 * MICROSOFT VISUAL STUDIO AND C++ PROGRAMMING Aims 1. Learning primary functions of Microsoft Visual Studio 2008 * 2. Introduction to C++ Programming 3. Running C++ programs using

More information

7/8/10 KEY CONCEPTS. Problem COMP 10 EXPLORING COMPUTER SCIENCE. Algorithm. Lecture 2 Variables, Types, and Programs. Program PROBLEM SOLVING

7/8/10 KEY CONCEPTS. Problem COMP 10 EXPLORING COMPUTER SCIENCE. Algorithm. Lecture 2 Variables, Types, and Programs. Program PROBLEM SOLVING KEY CONCEPTS COMP 10 EXPLORING COMPUTER SCIENCE Lecture 2 Variables, Types, and Programs Problem Definition of task to be performed (by a computer) Algorithm A particular sequence of steps that will solve

More information

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible) Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program

More information

(Refer Slide Time: 00:02:00)

(Refer Slide Time: 00:02:00) Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 18 Polyfill - Scan Conversion of a Polygon Today we will discuss the concepts

More information

To become familiar with array manipulation, searching, and sorting.

To become familiar with array manipulation, searching, and sorting. ELECTRICAL AND COMPUTER ENGINEERING 06-88-211: COMPUTER AIDED ANALYSIS LABORATORY EXPERIMENT #2: INTRODUCTION TO ARRAYS SID: OBJECTIVE: SECTIONS: Total Mark (out of 20): To become familiar with array manipulation,

More information

! A program is a set of instructions that the. ! It must be translated. ! Variable: portion of memory that stores a value. char

! A program is a set of instructions that the. ! It must be translated. ! Variable: portion of memory that stores a value. char Week 1 Operators, Data Types & I/O Gaddis: Chapters 1, 2, 3 CS 5301 Fall 2016 Jill Seaman Programming A program is a set of instructions that the computer follows to perform a task It must be translated

More information

Computer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons

Computer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons Computer Programming Basic Control Flow - Loops Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons Objectives To learn about the three types of loops: while for do To avoid infinite

More information

CS31 Discussion 1E. Jie(Jay) Wang Week3 Oct.12

CS31 Discussion 1E. Jie(Jay) Wang Week3 Oct.12 CS31 Discussion 1E Jie(Jay) Wang Week3 Oct.12 Outline Problems from Project 1 Review of lecture String, char, stream If-else statements Switch statements loops Programming challenge Problems from Project

More information

Tenka1 Programmer Contest/Tenka1 Programmer Beginner Contest 2018

Tenka1 Programmer Contest/Tenka1 Programmer Beginner Contest 2018 Tenka1 Programmer Contest/Tenka1 Programmer Beginner Contest 2018 DEGwer 2018/10/27 For International Readers: English editorial starts on page 5. A: Measure #include #include

More information

C++ Final Exam 2017/2018

C++ Final Exam 2017/2018 1) All of the following are examples of integral data types EXCEPT. o A Double o B Char o C Short o D Int 2) After the execution of the following code, what will be the value of numb if the input value

More information

Program Organization and Comments

Program Organization and Comments C / C++ PROGRAMMING Program Organization and Comments Copyright 2013 Dan McElroy Programming Organization The layout of a program should be fairly straight forward and simple. Although it may just look

More information

Chapter Four: Loops II

Chapter Four: Loops II Chapter Four: Loops II Slides by Evan Gallagher & Nikolay Kirov Chapter Goals To understand nested loops To implement programs that read and process data sets To use a computer for simulations Processing

More information

UNIVERSITY OF SWAZILAND SUPPLEMENTARY EXAMINATION, JULY 2013

UNIVERSITY OF SWAZILAND SUPPLEMENTARY EXAMINATION, JULY 2013 UNIVERSITY OF SWAZILAND SUPPLEMENTARY EXAMINATION, JULY 2013 Title of Paper : STRUCTURED PROGRAMMING - I Course number: CS243 Time allowed Instructions : Three (3) hours. : (1) Read all the questions in

More information

Chapter 5. Repetition. Contents. Introduction. Three Types of Program Control. Two Types of Repetition. Three Syntax Structures for Looping in C++

Chapter 5. Repetition. Contents. Introduction. Three Types of Program Control. Two Types of Repetition. Three Syntax Structures for Looping in C++ Repetition Contents 1 Repetition 1.1 Introduction 1.2 Three Types of Program Control Chapter 5 Introduction 1.3 Two Types of Repetition 1.4 Three Structures for Looping in C++ 1.5 The while Control Structure

More information

CSE030 Fall 2012 Final Exam Friday, December 14, PM

CSE030 Fall 2012 Final Exam Friday, December 14, PM CSE030 Fall 2012 Final Exam Friday, December 14, 2012 3-6PM Write your name here and at the top of each page! Name: Select your lab session: Tuesdays Thursdays Paper. If you have any questions or need

More information

2 nd Week Lecture Notes

2 nd Week Lecture Notes 2 nd Week Lecture Notes Scope of variables All the variables that we intend to use in a program must have been declared with its type specifier in an earlier point in the code, like we did in the previous

More information

Arrays. Elementary Data Representation Different Data Structure Operation on Data Structure Arrays

Arrays. Elementary Data Representation Different Data Structure Operation on Data Structure Arrays Arrays Elementary Data Representation Different Data Structure Operation on Data Structure Arrays Elementary Data Representation Data can be in the form of raw data, data items and data structure. Raw

More information

Today in CS161. Week #3. Learn about. Writing our First Program. See example demo programs. Data types (char, int, float) Input and Output (cin, cout)

Today in CS161. Week #3. Learn about. Writing our First Program. See example demo programs. Data types (char, int, float) Input and Output (cin, cout) Today in CS161 Week #3 Learn about Data types (char, int, float) Input and Output (cin, cout) Writing our First Program Write the Inches to MM Program See example demo programs CS161 Week #3 1 Data Types

More information

(6) The specification of a name with its type in a program. (7) Some memory that holds a value of a given type.

(6) The specification of a name with its type in a program. (7) Some memory that holds a value of a given type. CS 7A - Fall 2016 - Midterm 1 10/20/16 Write responses to questions 1 and 2 on this paper or attach additional sheets, as necessary For all subsequent problems, use separate paper Do not use a computer

More information

Computer Science II Lecture 2 Strings, Vectors and Recursion

Computer Science II Lecture 2 Strings, Vectors and Recursion 1 Overview of Lecture 2 Computer Science II Lecture 2 Strings, Vectors and Recursion The following topics will be covered quickly strings vectors as smart arrays Basic recursion Mostly, these are assumed

More information

Developed By Strawberry

Developed By Strawberry Experiment No. 3 PART A (PART A: TO BE REFFERED BY STUDENTS) A.1 Aim: To study below concepts of classes and objects 1. Array of Objects 2. Objects as a function argument 3. Static Members P1: Define a

More information

Review. Relational Operators. The if Statement. CS 151 Review #4

Review. Relational Operators. The if Statement. CS 151 Review #4 Review Relational Operators You have already seen that the statement total=5 is an assignment statement; that is, the integer 5 is placed in the variable called total. Nothing relevant to our everyday

More information

University of Waterloo CS240 Winter 2018 Assignment 2. Due Date: Wednesday, Jan. 31st (Part 1) resp. Feb. 7th (Part 2), at 5pm

University of Waterloo CS240 Winter 2018 Assignment 2. Due Date: Wednesday, Jan. 31st (Part 1) resp. Feb. 7th (Part 2), at 5pm University of Waterloo CS240 Winter 2018 Assignment 2 version: 2018-02-04 15:38 Due Date: Wednesday, Jan. 31st (Part 1) resp. Feb. 7th (Part 2), at 5pm Please read the guidelines on submissions: http://www.student.cs.uwaterloo.ca/~cs240/

More information

1st Midterm Exam: Solution COEN 243: Programming Methodology I

1st Midterm Exam: Solution COEN 243: Programming Methodology I 1st Midterm Exam: Solution COEN 243: Programming Methodology I Aishy Amer, Concordia University, Electrical and Computer Engineering February 10, 2005 Instructions: 1. Time Allowed is 1 Hour. Total Marks

More information

Here, type declares the base type of the array, which is the type of each element in the array size defines how many elements the array will hold

Here, type declares the base type of the array, which is the type of each element in the array size defines how many elements the array will hold Arrays 1. Introduction An array is a consecutive group of memory locations that all have the same name and the same type. A specific element in an array is accessed by an index. The lowest address corresponds

More information

Exercise 1.1 Hello world

Exercise 1.1 Hello world Exercise 1.1 Hello world The goal of this exercise is to verify that computer and compiler setup are functioning correctly. To verify that your setup runs fine, compile and run the hello world example

More information

Chapter Four: Loops. Slides by Evan Gallagher. C++ for Everyone by Cay Horstmann Copyright 2012 by John Wiley & Sons. All rights reserved

Chapter Four: Loops. Slides by Evan Gallagher. C++ for Everyone by Cay Horstmann Copyright 2012 by John Wiley & Sons. All rights reserved Chapter Four: Loops Slides by Evan Gallagher The Three Loops in C++ C++ has these three looping statements: while for do The while Loop while (condition) { statements } The condition is some kind of test

More information

LAB 4.1 Relational Operators and the if Statement

LAB 4.1 Relational Operators and the if Statement LAB 4.1 Relational Operators and the if Statement // This program tests whether or not an initialized value of num2 // is equal to a value of num1 input by the user. int main( ) int num1, // num1 is not

More information

Computer Programming : C++

Computer Programming : C++ The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2003 Muath i.alnabris Computer Programming : C++ Experiment #1 Basics Contents Structure of a program

More information

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305 Q.1 If h is any hashing function and is used to hash n keys in to a table of size m, where n

More information

EE 109 Lab 8a Conversion Experience

EE 109 Lab 8a Conversion Experience EE 109 Lab 8a Conversion Experience 1 Introduction In this lab you will write a small program to convert a string of digits representing a number in some other base (between 2 and 10) to decimal. The user

More information

Programming. C++ Basics

Programming. C++ Basics Programming C++ Basics Introduction to C++ C is a programming language developed in the 1970s with the UNIX operating system C programs are efficient and portable across different hardware platforms C++

More information

Chapter 2 C++ Fundamentals

Chapter 2 C++ Fundamentals Chapter 2 C++ Fundamentals 3rd Edition Computing Fundamentals with C++ Rick Mercer Franklin, Beedle & Associates Goals Reuse existing code in your programs with #include Obtain input data from the user

More information

Examination for the Second Term - Academic Year H Mid-Term. Name of student: ID: Sr. No.

Examination for the Second Term - Academic Year H Mid-Term. Name of student: ID: Sr. No. Kingdom of Saudi Arabia Ministry of Higher Education Course Code: ` 011-COMP Course Name: Programming language-1 Deanship of Preparatory Year Jazan University Total Marks: 20 Duration: 60 min Group: Examination

More information

1. In C++, reserved words are the same as predefined identifiers. a. True

1. In C++, reserved words are the same as predefined identifiers. a. True C++ Programming From Problem Analysis to Program Design 8th Edition Malik TEST BANK Full clear download (no formatting errors) at: https://testbankreal.com/download/c-programming-problem-analysis-program-design-8thedition-malik-test-bank/

More information

The following program computes a Calculus value, the "trapezoidal approximation of

The following program computes a Calculus value, the trapezoidal approximation of Multicore machines and shared memory Multicore CPUs have more than one core processor that can execute instructions at the same time. The cores share main memory. In the next few activities, we will learn

More information

Elements of C in C++ data types if else statement for loops. random numbers rolling a die

Elements of C in C++ data types if else statement for loops. random numbers rolling a die Elements of C in C++ 1 Types and Control Statements data types if else statement for loops 2 Simulations random numbers rolling a die 3 Functions and Pointers defining a function call by value and call

More information

pointers + memory double x; string a; int x; main overhead int y; main overhead

pointers + memory double x; string a; int x; main overhead int y; main overhead pointers + memory computer have memory to store data. every program gets a piece of it to use as we create and use more variables, more space is allocated to a program memory int x; double x; string a;

More information

Introduction to C++ Lecture Set 2. Introduction to C++ Week 2 Dr Alex Martin 2013 Slide 1

Introduction to C++ Lecture Set 2. Introduction to C++ Week 2 Dr Alex Martin 2013 Slide 1 Introduction to C++ Lecture Set 2 Introduction to C++ Week 2 Dr Alex Martin 2013 Slide 1 More Arithmetic Operators More Arithmetic Operators In the first session the basic arithmetic operators were introduced.

More information

Why Is Repetition Needed?

Why Is Repetition Needed? Why Is Repetition Needed? Repetition allows efficient use of variables. It lets you process many values using a small number of variables. For example, to add five numbers: Inefficient way: Declare a variable

More information

Problem Solving: Storyboards for User Interaction

Problem Solving: Storyboards for User Interaction Topic 6 1. The while loop 2. Problem solving: hand-tracing 3. The for loop 4. The do loop 5. Processing input 6. Problem solving: storyboards 7. Common loop algorithms 8. Nested loops 9. Problem solving:

More information

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

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible) Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program

More information

MA 511: Computer Programming Lecture 3: Partha Sarathi Mandal

MA 511: Computer Programming Lecture 3: Partha Sarathi Mandal MA 511: Computer Programming Lecture 3: http://www.iitg.ernet.in/psm/indexing_ma511/y10/index.html Partha Sarathi Mandal psm@iitg.ernet.ac.in Dept. of Mathematics, IIT Guwahati Semester 1, 2010-11 Last

More information

Other operators. Some times a simple comparison is not enough to determine if our criteria has been met.

Other operators. Some times a simple comparison is not enough to determine if our criteria has been met. Lecture 6 Other operators Some times a simple comparison is not enough to determine if our criteria has been met. For example: (and operation) If a person wants to login to bank account, the user name

More information

CS13002 Programming and Data Structures, Spring 2005

CS13002 Programming and Data Structures, Spring 2005 CS13002 Programming and Data Structures, Spring 2005 Mid-semester examination : Solutions Roll no: FB1331 Section: @ Name: Foolan Barik Answer all questions. Write your answers in the question paper itself.

More information

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.

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. 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. B. Outputs to the console a floating point number f1 in scientific format

More information

CHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++

CHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++ CHAPTER 9 C++ 1. WRITE ABOUT THE BINARY OPERATORS USED IN C++? ARITHMETIC OPERATORS: Arithmetic operators perform simple arithmetic operations like addition, subtraction, multiplication, division etc.,

More information

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program Overview - General Data Types - Categories of Words - The Three S s - Define Before Use - End of Statement - My First Program a description of data, defining a set of valid values and operations List of

More information

The sequence of steps to be performed in order to solve a problem by the computer is known as an algorithm.

The sequence of steps to be performed in order to solve a problem by the computer is known as an algorithm. CHAPTER 1&2 OBJECTIVES After completing this chapter, you will be able to: Understand the basics and Advantages of an algorithm. Analysis various algorithms. Understand a flowchart. Steps involved in designing

More information

The American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011

The American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011 The American University in Cairo Department of Computer Science & Engineering CSCI 106-07&09 Dr. KHALIL Exam-I Fall 2011 Last Name :... ID:... First Name:... Form I Section No.: EXAMINATION INSTRUCTIONS

More information

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

CPE 112 Spring 2015 Exam III (100 pts) April 8, True or False (12 Points) Name rue or False (12 Points) 1. (12 pts) Circle for true and F for false: F a) Local identifiers have name precedence over global identifiers of the same name. F b) Local variables retain their value

More information

Programming Language. Functions. Eng. Anis Nazer First Semester

Programming Language. Functions. Eng. Anis Nazer First Semester Programming Language Functions Eng. Anis Nazer First Semester 2016-2017 Definitions Function : a set of statements that are written once, and can be executed upon request Functions are separate entities

More information

I/O Streams and Standard I/O Devices (cont d.)

I/O Streams and Standard I/O Devices (cont d.) Chapter 3: Input/Output Objectives In this chapter, you will: Learn what a stream is and examine input and output streams Explore how to read data from the standard input device Learn how to use predefined

More information

More About Factoring Trinomials

More About Factoring Trinomials Section 6.3 More About Factoring Trinomials 239 83. x 2 17x 70 x 7 x 10 Width of rectangle: Length of rectangle: x 7 x 10 Width of shaded region: 7 Length of shaded region: x 10 x 10 Area of shaded region:

More information

Lecture # 6. Repetition. Review. If Else Statements Comparison Operators Boolean Expressions Nested Ifs. Switch Statements.

Lecture # 6. Repetition. Review. If Else Statements Comparison Operators Boolean Expressions Nested Ifs. Switch Statements. Lecture # 6 Repetition Review If Else Statements Comparison Operators Boolean Expressions Nested Ifs Dangling Else Switch Statements 1 While loops Syntax for the While Statement (Display 2.11 - page 76)

More information

How to approach a computational problem

How to approach a computational problem How to approach a computational problem A lot of people find computer programming difficult, especially when they first get started with it. Sometimes the problems are problems specifically related to

More information

UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

More information

Study recommendations for Quiz 5 - Chapter 5

Study recommendations for Quiz 5 - Chapter 5 Study recommendations for Quiz 5 - Chapter 5 Review Chapter 5 content in: your textbook, the Example Pages, and in the Glossary on the website Review the revised Order of Precedence able (including arithmetic,

More information

Chapter 01 Arrays Prepared By: Dr. Murad Magableh 2013

Chapter 01 Arrays Prepared By: Dr. Murad Magableh 2013 Chapter 01 Arrays Prepared By: Dr. Murad Magableh 2013 One Dimensional Q1: Write a program that declares two arrays of integers and fills them from the user. Then exchanges their values and display the

More information

Programming 1. Lecture 6 Structured data types. Arrays

Programming 1. Lecture 6 Structured data types. Arrays Programming 1 Lecture 6 Structured data types. Arrays Objectives Understand the difference between simple and structured data types Manage the following structured data types: one-dimensional and two-dimensional

More information

CS101 PLEDGED SPRING 2001

CS101 PLEDGED SPRING 2001 The following exam is pledged. All answers are to be given on the provided answer sheet. The test is closed book, closed note, and closed calculator. If you believe more than one answer is acceptable,

More information

Arrays. Week 4. Assylbek Jumagaliyev

Arrays. Week 4. Assylbek Jumagaliyev Arrays Week 4 Assylbek Jumagaliyev a.jumagaliyev@iitu.kz Introduction Arrays Structures of related data items Static entity (same size throughout program) A few types Pointer-based arrays (C-like) Arrays

More information

CS Semester I. Quiz 1 (version A)

CS Semester I. Quiz 1 (version A) Your Department Degree Program Roll Number: CS 101 015-16 Semester I. Quiz 1 (version A) August 8th, 015. 80am-910am (50 minutes). Marks: 1, Weight: 10% There are 1 questions in this quiz, on 8 pages (4

More information

CHAPTER 3 BASIC INSTRUCTION OF C++

CHAPTER 3 BASIC INSTRUCTION OF C++ CHAPTER 3 BASIC INSTRUCTION OF C++ MOHD HATTA BIN HJ MOHAMED ALI Computer programming (BFC 20802) Subtopics 2 Parts of a C++ Program Classes and Objects The #include Directive Variables and Literals Identifiers

More information

Arithmetic Operators. Binary Arithmetic Operators. Arithmetic Operators. A Closer Look at the / Operator. A Closer Look at the % Operator

Arithmetic Operators. Binary Arithmetic Operators. Arithmetic Operators. A Closer Look at the / Operator. A Closer Look at the % Operator 1 A Closer Look at the / Operator Used for performing numeric calculations C++ has unary, binary, and ternary s: unary (1 operand) - binary ( operands) 13-7 ternary (3 operands) exp1? exp : exp3 / (division)

More information

Superior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.6

Superior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.6 Superior University Department of Electrical Engineering CS-115 Computing Fundamentals Experiment No.6 Pre-Defined Functions, User-Defined Function: Value Returning Functions Prepared for By: Name: ID:

More information

Welcome to MCS 360. content expectations. using g++ input and output streams the namespace std. Euclid s algorithm the while and do-while statements

Welcome to MCS 360. content expectations. using g++ input and output streams the namespace std. Euclid s algorithm the while and do-while statements Welcome to MCS 360 1 About the Course content expectations 2 our first C++ program using g++ input and output streams the namespace std 3 Greatest Common Divisor Euclid s algorithm the while and do-while

More information

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures The main body and cout Agenda 1 Fundamental data types Declarations and definitions Control structures References, pass-by-value vs pass-by-references The main body and cout 2 C++ IS AN OO EXTENSION OF

More information

Superior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.1

Superior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.1 Superior University Department of Electrical Engineering CS-115 Computing Fundamentals Experiment No.1 Introduction of Compiler, Comments, Program Structure, Input Output, Data Types and Arithmetic Operators

More information

Practice Exercises #8

Practice Exercises #8 Practice Exercises #8 Chapter 6 Functions Page 1 Practice Exercises #8 Functions Related Chapter Chapter Title 6 Functions STUDENT LEARNING OUTCOMES: Upon completion of this practical exercise, a successful

More information

(b) Write a statement that prints the length of the string s (apply appropriate function!):

(b) Write a statement that prints the length of the string s (apply appropriate function!): CS111 Lab 26 Goal: Learn how to use string functions. Practice on thinking string as character array. Before you start working on the exercises below, go through the example codes and reference materials

More information

Object oriented programming

Object oriented programming Exercises 3 Version 1.0, 24 February, 2017 Table of Contents 1. Classes...................................................................... 1 1.1. Defining class..........................................................

More information

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

FORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each): FORM 1 (Please put your name and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each): 1. The basic commands that a computer performs are input (get data), output (display result),

More information