FALL 2017 CSCI 304 LAB1 (Due on Sep-19, 11:59:59pm)

Similar documents
SPRING 2017 CSCI 304 LAB1 (Due on Feb-14, 11:59:59pm)

Introduction: The Unix shell and C programming

CS261: HOMEWORK 2 Due 04/13/2012, at 2pm

COMP s1 Lecture 1

CpSc 1011 Lab 3 Integer Variables, Mathematical Operations, & Redirection

Fundamentals of Programming Session 4

Programming for Engineers Arrays

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

Final Exam 1 /12 2 /12 3 /10 4 /7 5 /4 6 /10 7 /8 8 /9 9 /8 10 /11 11 /8 12 /10 13 /9 14 /13 15 /10 16 /10 17 /12. Faculty of Computer Science

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function

Pointers (part 1) What are pointers? EECS We have seen pointers before. scanf( %f, &inches );! 25 September 2017

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

EECE.2160: ECE Application Programming

1. Introduction. 2. Deliverables

Programming for Engineers Introduction to C

C Concepts - I/O. Lecture 19 COP 3014 Fall November 29, 2017

ESC101N: Fundamentals of Computing End-sem st semester

CpSc 1111 Lab 4 Part a Flow Control, Branching, and Formatting

C Introduction. Comparison w/ Java, Memory Model, and Pointers

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

A First Book of ANSI C Fourth Edition. Chapter 8 Arrays

Arrays and Pointers (part 1)

CS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function

C mini reference. 5 Binary numbers 12

CpSc 1111 Lab 5 Formatting and Flow Control

PRINCIPLES OF OPERATING SYSTEMS

CSCI 2132 Final Exam Solutions

BLM2031 Structured Programming. Zeyneb KURT

CpSc 1111 Lab 9 2-D Arrays

Introduction to Programming. Lecture 2: Introduction to C

Full file at C How to Program, 6/e Multiple Choice Test Bank

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

Arrays and Pointers. CSE 2031 Fall November 11, 2013

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

CpSc 1111 Lab 6 Conditional Statements, Loops, the Math Library, and Random Numbers What s the Point?

CpSc 1011 Lab 5 Conditional Statements, Loops, ASCII code, and Redirecting Input Characters and Hurricanes

Fundamental of Programming (C)

C BOOTCAMP DAY 2. CS3600, Northeastern University. Alan Mislove. Slides adapted from Anandha Gopalan s CS132 course at Univ.

Computer Programming. C Array is a collection of data belongings to the same data type. data_type array_name[array_size];

We first learn one useful option of gcc. Copy the following C source file to your

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

Compiling and Running a C Program in Unix

CS : Programming for Non-Majors, Fall 2018 Programming Project #5: Big Statistics Due by 10:20am Wednesday November

Arrays and Pointers. Arrays. Arrays: Example. Arrays: Definition and Access. Arrays Stored in Memory. Initialization. EECS 2031 Fall 2014.

EECE.2160: ECE Application Programming

CS 356, Fall 2018 Data Lab (Part 2): Manipulating Bits Due: Mon, Sep. 17, 11:59PM

A3-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH 'C' LANGUAGE

CS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015

A Fast Review of C Essentials Part I

Subject: Fundamental of Computer Programming 2068

CSE 351. GDB Introduction

CpSc 111 Lab 3 Integer Variables, Mathematical Operations, & Redirection

Mid-term Exam. Fall Semester 2017 KAIST EE209 Programming Structures for Electrical Engineering. Name: Student ID:

Arrays and Pointers (part 1)

Computer Science & Engineering 150A Problem Solving Using Computers

FALL 2017 CSCI 304 LAB2 (Due on October-10, 11:59:59pm)

C How to Program, 7/e by Pearson Education, Inc. All Rights Reserved.

Fundamentals of Programming. Lecture 3: Introduction to C Programming

ENCE 3241 Data Lab. 60 points Due February 19, 2010, by 11:59 PM

Approximately a Final Exam CPSC 206

C Fundamentals & Formatted Input/Output. adopted from KNK C Programming : A Modern Approach

CS 356, Fall 2018 Data Lab (Part 1): Manipulating Bits Due: Wednesday, Sep. 5, 11:59PM

Integer Representation. Variables. Real Representation. Integer Overflow/Underflow

Class Information ANNOUCEMENTS

Slide Set 3. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

C: How to Program. Week /Mar/05

United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017

Introduction to C. Systems Programming Concepts

Mid-term Exam. Fall Semester 2017 KAIST EE209 Programming Structures for Electrical Engineering. Name: Student ID:

CSE 5A Introduction to Programming I (C) Homework 4

School of Computer Science Introduction to Algorithms and Programming Winter Midterm Examination # 1 Wednesday, February 11, 2015

CSCI 2132 Final Exam Solutions

Basic and Practice in Programming Lab7

APT Session 4: C. Software Development Team Laurence Tratt. 1 / 14

CSCI 2132 Software Development. Lecture 8: Introduction to C

Introduction to C Programming

Introduction to C Language (M3-R )

SU2017. LAB 1 (May 4/9) Introduction to C, Function Declaration vs. Definition, Basic I/O (scanf/printf, getchar/putchar)

Chapter 2 - Introduction to C Programming

Chapter 2 (Dynamic variable (i.e. pointer), Static variable)

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9

Topic 6: A Quick Intro To C. Reading. "goto Considered Harmful" History

CSE101-Lec#17. Arrays. (Arrays and Functions) Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU. LPU CSE101 C Programming

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 1

C programming basics T3-1 -

Pointers. Part VI. 1) Introduction. 2) Declaring Pointer Variables. 3) Using Pointers. 4) Pointer Arithmetic. 5) Pointers and Arrays

C Overview Fall 2014 Jinkyu Jeong

EM108 Software Development for Engineers

Warm-up sheet: Programming in C

CS : Programming for Non-majors, Fall 2018 Programming Project #2: Census Due by 10:20am Wednesday September

ONE DIMENSIONAL ARRAYS

COMS W3101 Programming Language: C++ (Fall 2015) Ramana Isukapalli

CpSc 1011 Lab 4 Formatting and Flow Control Windchill Temps

Topic 6: A Quick Intro To C

CSE101-lec#12. Designing Structured Programs Introduction to Functions. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU

CSC231 C Tutorial Fall 2018 Introduction to C

Chapter 1 & 2 Introduction to C Language

today cs3157-fall2002-sklar-lect05 1

ECE264 Fall 2013 Exam 1, September 24, 2013

Transcription:

FALL 2017 CSCI 304 LAB1 (Due on Sep-19, 11:59:59pm) Objectives: Debugger Standard I/O Arithmetic statements Conditional structures Looping structures File I/O Strings Pointers Functions Structures Important data structure related to pointers, Linked List operations REMINDERS: Ø Every lab requires a README file. This file should include the following: o Student name(s) - to avoid the 10% deduction (as explained in the course syllabus) o Effort distribution for each contributor (assumed 100% if you are not working with a partner) o Total amount of time to complete the entire lab o Short description of any concerns, interesting problems or discoveries encountered, or comments in general about the contents of the lab o Directions on how to run the solution(s), as needed Ø You should aim to always hand an assignment in on time. If you are late (even by a minute or heaven forbid, less than a minute late), you will receive 50% of your earned points for the designated grade as long as the assignment is submitted by 11:59pm the following day, based on the due date listed on the syllabus and confirmed by the instructor. If you are more than 24 hours late, you will receive a zero for the assignment and your assignment will not be graded at all. Ø Any lab submitted that does not compile and run WILL RECEIVE AN AUTOMATIC GRADE OF ZERO. No exceptions will be made for this rule - to achieve even a single point on a lab your code must minimally compile and execute without crashing. Ø You are welcome to do more than what is required by the assignment as long as it is clear what you are doing and it does not interfere with the mandatory requirements. Ø You are responsible for making sure that your lab submits correctly. Ø Be sure that you are aware of the Coding Style file information posted on my Day by Day website. GRADING CRITERIA (approximate percentages listed) Ø (20%) The code and algorithm are well commented. A code block should be included in the main program including the programmer name(s) as well as explaining the nature of the problem and an overall method of the solution (what you are doing, not how). A short comment should be included for each logical or syntactic block of statements Ø (20%) The program should be appropriate to the assignment, well- structured and easy to understand without complicated and confusing flow of control. Ø (60%) The results are correct, verifiable, and well- formatted. The program correctly performs as assigned.

LAB DESCRIPTION PART 1 (15%) Debugger Questions. Mandatory file name à lab1p1.txt Type in the following program with the name gdbtest.c Make sure your program compiles and runs correctly. Compile the program using the GDB (the GNU debugger) option: gcc g o gdbtest gdbtest.c If you would like, create a program text file once your program compiles correctly with the line numbers (as shown in class) or use the list command. Run the program in the GDB environment by typing: gdb gdbtest You should see the GDB prompt which looks like this: (gdb) Choose 5 different debugger commands and test them out on your program. Write a small paragraph for each command and specify why you used it and what it did. Order the commands in such a way that someone could follow your directions to walk through them consecutively to learn about GDB. #include <stdio.h> #include <stdlib.h> int main (void) int i = 2; while (i < 256) i = square(i); printf ("%d\n", i); return (EXIT_SUCCESS); int square (int x) int y = x * x; return (x * x); PART 2 (20%). Mandatory filename à lab1p2q1.c lab1p2q2.c Q1: Output Practice (10%): In the introductory program we include the library <stdio.h>, which contains the function printf. This function is used to produce output in the form of characters that are printed in the terminal. In its simplest form, the function is called with a string as argument: printf("hello World!\n"); That is great, but we want our programs to output more than just the fixed strings that the programmer writes in the program. To print the contents of variables, we add format specifiers to the string and add the variables we want to print as arguments: int number; char letter; printf("%d is an integer and %c is a character\n", number, letter); Different types of variables have different specifiers, all starting with a percentage sign. Common specifiers are %d for integers, %f for floats, %c for characters and %s for strings. To output a percentage sign, we use %%. Write a function that outputs: a) The string: One half is 50% b) two integers and their difference. c) two floats and the result of dividing one with the other Write a main function that calls your other functions. The output has to be as follows:

$./lab1p2q1 One half is 50% The difference between 10 and 3 is 7 1.000000 / 3.000000 is 0.333333 $ //Notice this newline Q2: Input Practice (10%): For input we use the function scanf, also from the library <stdio.h>. The scanf function takes a format string followed by references to where the input should be stored. Example that reads an integer to a variable: int number; scanf("%d", &number); Notice that the & character in front of the variable name. It means that the variable is passed as reference to scanf. It allows scanf to update the value of the variable. If & is not there, the program would likely crash at that point. When reading a string, the & sign can be omitted: char my_variable[100]; scanf("%s", my_variable); Write functions that: a) asks for two integers and outputs them and their sum. b) asks for two floats and outputs their product. c) asks for a word and prints it twice on the same row. Write a main function that calls your other functions. The output has to be as follows: $./lab1p2q2 Give two integers: 12 5 You entered 12 and 5, their sum is: 17 Give two floats: 3.14 2 You entered 3.140000 and 2.000000, their product is: 6.280000 Give a word: Yey! Yey! Yey! $ //Notice this newline PART 3. SIMPLE CIPHER (25%) Mandatory filename à lab1p3.c PROBLEM: Ø You have a message that you want to encode. The scheme to encode the message is to reverse each word in the phrase where words are separated by one or more non- alphabetic characters; and keep each non- alphabetic character in their original position. Thus, the output string and the input string should be the same length.

Ø You will need to use the underscore character _ instead of a blank for the input in order to read it in as a single text value. However, when you create your encoded output, be sure to convert the underscore to a blank. Ø In addition, output all alphabetic characters as upper case letters. INPUT/OUTPUT: Ø Input file name: lab1p3in Ø Output file name: lab1p3out Ø Example Input à Output: War_eagle à RAW ELGAE Reading_records_of_variable_length? à GNIDAER SDROCER FO ELBAIRAV HTGNEL? Have_fun._Doing_this_lab_:) à EVAH NUF. GNIOD SIHT BAL :) Words%end*with^non- alpha characters!!! à SDROW%DNE*HTIW^NON- AHPLA SRETCARAHC!!! CONSTRAINTS: The length of the input message to be encoded will not exceed 100 characters, including the new line character (after all, texting has a character limit so why can t we?) Do not use subscripts for this lab; use pointers to manipulate the location of each character in the array(s) PART 4. LINKED LIST (40%) Mandatory filename à lab1p4.c PROBLEM: Write the following structs: Ø Create the structure Node that contains the following members: o data: a char pointer (char*). o next: a pointer to the structure Node. Ø Create the structure Linkedlist that contains the following members: o head: a pointer to structure Node. Write a program that does the following in the main function: Ø Your program should read arguments. Ø Declare a linked list LL. Don t forget to initialize the head of the Linked List. Ø Insert the arguments that start with an uppercase letter at the beginning of the Linked List in the order they arrived in. Use insertatbeginning. Ø Insert the arguments that start with a lowercase letter at the end of the Linked List in the order they arrived in. Use insertattheend. Ø Before inserting, check if the word exist in the Linked List using findnode. if it exist, delete it using deletenode. Ø Print the linked list data using displaylinkedlist. Write the following functions: Ø Write the function insertatbeginning that takes a pointer to structure Linked List LL and a string ele. Allocates a node using malloc or calloc, then inserts it into the beginning of the linked list. As for the data, get the size of ele using strlen, allocate a string, and then copy the string to it using strcpy. o void insertatbeginning(struct Linkedlist* LL, char ele[]);

Ø Write the function insertattheend that takes a pointer to structure Linked List LL and a string ele. Allocates a node using malloc or calloc, then inserts it at the end of the linked list. As for the data, get the size of ele using strlen, allocate a string, and then copy the string to it using strcpy. o void insertattheend(struct Linkedlist* LL, char ele[]); Ø Write the function deletenode that takes a pointer to structure Linked List LL and a string ele. Then removes the node with the sting in its data from the linked list and frees its space. Don t forget to free the string s space too. o void deletenode(struct Linkedlist* LL, char ele[]); Ø Write the function findnode that takes a structure Linked List LL and string ele. Then return 1 if ele exist. Otherwise, return 0. o int findnode(struct Linkedlist LL, char ele[]); Ø Write the function displaylinkedlist that takes a structure Linked List LL. Then prints all the linked list s nodes data separated by commas. o void displaylinkedlist(struct Linkedlist LL); Sample Runs: $./lab1p4 ERROR: The program must read at least an argument. $./lab1p4 my name is Marwan and my car is White The list:- White, Marwan, name, and, car CONSTRAINTS: The input string will be split by space as sample runs. LAB SUBMISSION You should submit all your lab assignments electronically using the submit command. The format of submit command is as follows: ~zpeng/bin/submit cs304 labname files- or- directory- to- submit where, the cs304 is different per course section, labname is the lab you are working on (lab1, lab2, etc.) and files- or- directory- to- submit is a list of the file(s) or directory that make up the lab. The labname for this lab is: Be sure to submit the following files: lab1 lab1p1.txt lab1p2q1.c lab1p2q2.c lab1p3.c lab1p4.c README For example, for this lab, the submit command should be: ~zpeng/bin/submit cs304 lab1 lab1p1.txt lab1p2q1.c lab1p2q2.c lab1p3.c lab1p4.c README And Please Make Sure: all the files are in current directory where you type submit command. NOTE: All of the files in a lab MUST be submitted using one command. If you use two submit commands, the second one erases the files from the first submission. Do not press the enter key in the middle of your submit command line; let it wrap if necessary. Your programs MUST be submitted in source code form. Make sure that you submit the *.c (and *.h files when necessary). Do NOT submit the object files (*.o) and/or the executable. It is YOUR responsibility to make sure your code can compile and run on CS department server me.cs.wm.edu.