Programming Assignment #1 12-Month Calendar—

Slides:



Advertisements
Similar presentations
Introduction to C Systems Programming Concepts. Introduction to C A simple C Program A simple C Program –Variable Declarations –printf ( ) Compiling and.
Advertisements

Dale Roberts Basic I/O – scanf() CSCI 230 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Department of.
CS1061 C Programming Lecture 16: Formatted I/0 A. O’Riordan, 2004.
1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf 9.4Printing Integers 9.5Printing Floating-Point.
Differences between Java and C CS-2303, C-Term Differences between Java and C CS-2303, System Programming Concepts (Slides include materials from.
Display a 12-Month Calendar CS-2301 D-term Programming Assignment #2 12-Month Calendar CS-2301 System Programming C-term 2009 (Slides include materials.
1 Lecture 2  Input-Process-Output  The Hello-world program  A Feet-to-inches program  Variables, expressions, assignments & initialization  printf()
More on Numerical Computation CS-2301 B-term More on Numerical Computation CS-2301, System Programming for Non-majors (Slides include materials from.
Chapter 9 Formatted Input/Output Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction.
Assignment #2, 12- month Calendar CS-2301, B-Term Programming Assignment #2 12-Month Calendar CS-2301, System Programming for Non-Majors (Slides.
C Formatted Input/Output /* Using Integer Conversion Specifiers */ #include int main ( ) { printf( "%d\n", 455 ); printf( "%i\n", 455 ); printf( "%d\n",
The printf Method The printf method is another way to format output. It is based on the printf function of the C language. System.out.printf(,,,..., );
Ping Zhang 10/08/2010.  You can get data from the user (input) and display information to the user (output).  However, you must include the library.
Input/Output  Input/Output operations are performed using input/output functions  Common input/output functions are provided as part of C’s standard.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Streams Streams –Sequences of characters organized.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction.
1 IPC144 Session 11 The C Programming Language. 2 Objectives To format a #define statement correctly To use a #define statement in a C program To construct.
Chapter 9 Formatted Input/Output. Objectives In this chapter, you will learn: –To understand input and output streams. –To be able to use all print formatting.
Chapter 3: Formatted Input/Output Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Chapter 3 Formatted Input/Output.
CMSC 202 Java Console I/O. July 25, Introduction Displaying text to the user and allowing the user to enter text are fundamental operations performed.
Lecture 1 cis208 January 14 rd, Compiling %> gcc helloworld.c returns a.out %> gcc –o helloworld helloworld.c returns helloworld.
3. FORMATTED INPUT/OUTPUT. The printf Function The first argument in a call of printf is a string, which may contain both ordinary characters and conversion.
CSE1301 Computer Programming: Lecture 6 Input/Output.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Input and Output.
Operating System Discussion Section. The Basics of C Reference: Lecture note 2 and 3 notes.html.
CS 1704 Introduction to Data Structures and Software Engineering.
Chapter 3: Formatted Input/Output 1 Chapter 3 Formatted Input/Output.
Formatted I/O ä ä Standard Output ä ä printf() family of functions ä ä Standard Input ä ä scanf() family of functions.
Chapter 9 - Formatted Input/Output
C Formatted Input/Output
Formatted Input and Output
ECE Application Programming
Input/output.
TMF1414 Introduction to Programming
Chapter 3: I/O Management
Introduction to C CSE 2031 Fall /3/ :33 AM.
OUTPUT STATEMENTS GC 201.
Programming in C Input / Output.
Input and Output Lecture 4.
Input/Output Input/Output operations are performed using input/output functions Common input/output functions are provided as part of C’s standard input/output.
Formatted Input/Output
Programming in C Input / Output.
Formatting Output.
Programming Assignment #4 Binary Trees in C++
CSI 121 Structured Programming Language Lecture 7: Input/Output
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
Lecture 13 Input/Output Files.
Chapter 9 - Formatted Input/Output
Strings and Streams Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition,
Structures, Unions, and Typedefs
Symbolic Constants in C
Programming Assignment #6
Scope Rules and Storage Types
Programming Assignment #5
Differences between Java and C
Your first C and C++ programs
Operator Overloading Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition,
Programming in C Input / Output.
Formatted Input/Output
Conversion Check your class notes and given examples at class.
Functions in C and C++ CS-2303 System Programming Concepts Hugh C. Lauer (Slides include materials from The C Programming Language, 2nd edition, by Kernighan.
Digression on Loop Invariants
EECE.2160 ECE Application Programming
Formatted Input/Output
Introduction to C EECS May 2019.
EECE.2160 ECE Application Programming
Introduction to C Programming
CS 1054 Introduction to Programming in Java
Introduction to C CSE 2031 Fall /15/2019 8:26 AM.
Presentation transcript:

Programming Assignment #1 12-Month Calendar— Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition, by Kernighan and Ritchie, Absolute C++, by Walter Savitch, The C++ Programming Language, Special Edition, by Bjarne Stroustrup, and from C: How to Program, 5th and 6th editions, by Deitel and Deitel) CS-2303, A-Term 2012 PA1 — Twelve Month Calendar

PA1 — Twelve Month Calendar Goals and Objectives Develop a simple C program on a Linux platform based on your Java skills Become familiar with C idiosyncrasies pertaining to loops, switches, and conditional statements Learn to use formatted input and output in C CS-2303, A-Term 2012 PA1 — Twelve Month Calendar

Display a 12-Month Calendar Prompt for a non-negative year number (e.g., 2012) Determine starting day-of-the-week and whether or not it is a leap year Print calendar for twelve months for that year CS-2303, A-Term 2012 PA1 — Twelve Month Calendar

Sample Output (fragment) January Sun Mon Tue Wed Thu Fri Sat 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 February Sun Mon Tue Wed Thu Fri Sat 1 2 3 4 5 6 7 8 9 10 11 12 13 14 … Two spaces between days Note – right justified under day of week CS-2303, A-Term 2012 PA1 — Twelve Month Calendar

PA1 — Twelve Month Calendar Implementation Loop statements — similar to Java for loop while loop Nested loops Conditional statements — also similar to Java if-else statement switch and break statements Function declarations — similar to Java, but not part of any class Calling functions is similar to Java Formatted input and output — very different from Java CS-2303, A-Term 2012 PA1 — Twelve Month Calendar

PA1 — Twelve Month Calendar Hints Think through the data you need to keep track of Which month and how many days per month Which day of week and when to start new line Think through how to organize loops to Cycle through the months Cycle through the days within a month Communicate day of week from one month to next Ask questions next time! CS-2303, A-Term 2012 PA1 — Twelve Month Calendar

PA1 — Twelve Month Calendar printf() & scanf() Prints a string in which each conversion specifier is replaced with value of corresponding argument int printf("string in double quotes", arg1, arg2, arg3, …); Conversion specifier:– Part of the "string in double quotes" Begins with '%' character Describes how to print one argument ith conversion specifier in string says how to print argi Resulting string printed on stdout Returns number of characters printed! Note – the "... " means that the number of arguments is open-ended CS-2303, A-Term 2012 PA1 — Twelve Month Calendar

PA1 — Twelve Month Calendar printf() (continued) %d, %i — decimal number %u — unsigned decimal number %c — character %s — string %f — floating point number e.g., 3.14159 %e, E — floating point number e.g., 2.9979e+8 or 2.9979E+8 %% — a single ‘%’ character See K&R textbook for full list (pp 154, 244) CS-2303, A-Term 2012 PA1 — Twelve Month Calendar

printf() Optional Controls ^ – minimum field width Padded on left ^ – precision of number or minimum number of digits for decimal number %.12s ^ – width of string %-6.4f ^ – indicates left justify Padded on right CS-2303, A-Term 2012 PA1 — Twelve Month Calendar

PA1 — Twelve Month Calendar printf() Examples int j = 24; float twoPi = 2 * pi; printf("j=%d, k=%f\n", j, twoPi ); Output j=24, k=6.28319 Return from printf() = 16 printf("%4d %4d %4d %6d", 1, 10, 100, 1000); 1 10 100 1000 .. .. .. .. .. .. .. .. CS-2303, A-Term 2012 PA1 — Twelve Month Calendar

PA1 — Twelve Month Calendar scanf() Reads input, decomposes into individual variables Opposite of printf() scanf("string in double quotes", &arg1, &arg2, &arg3, …); Arguments must be locations – use ‘&’ Converts input string according to scan string, stores in variables Returns number of matched and stored items Or the value EOF if end of file is encountered Stops at end of argument string or when no match is found CS-2303, A-Term 2012 PA1 — Twelve Month Calendar

PA1 — Twelve Month Calendar scanf() Examples int i; double x; char c; scanf("%d%f%c", &i, &x, &c); Looks first for an integer Skips white space, including newline characters Looks next for a floating point Looks next for a single character Does not skip white space; returns the first character it finds CS-2303, A-Term 2012 PA1 — Twelve Month Calendar

PA1 — Twelve Month Calendar scanf() Formats %d — any decimal number %u — an unsigned integer %c — character White space not skipped %e, f, g — floating point number %s — string Defer to later in the course %% — matches a single ‘%’ character Any other character Matches that character CS-2303, A-Term 2012 PA1 — Twelve Month Calendar

PA1 — Twelve Month Calendar scanf() Formats Must specify 'h' or 'l' indicating short or long integer, float vs. double %d — any decimal number %u — an unsigned integer %c — character White space not skipped %e, f, g — floating point number %s — string Defer to later in the course %% — matches a single '%' character Any other character Matches that character CS-2303, A-Term 2012 PA1 — Twelve Month Calendar

PA1 — Twelve Month Calendar Summary of Assignment Prompt user for a non-negative year number (e.g., 2012) Determine starting day-of-the-week and whether or not it is a leap year Print calendar for twelve months for that year CS-2303, A-Term 2012 PA1 — Twelve Month Calendar

PA1 — Twelve Month Calendar Submission Submit on Turnin as PA1 Program name PA1.c Project value:– 20 points Rules:– Program must compile without warnings On CCC systems Program must be named PA1.c CS-2303, A-Term 2012 PA1 — Twelve Month Calendar

Questions on Assignment? Digression on Loop Invariants CS-2303, A-Term 2012 PA1 — Twelve Month Calendar