Display a 12-Month Calendar CS-2301 D-term 20091 Programming Assignment #2 12-Month Calendar CS-2301 System Programming C-term 2009 (Slides include materials.

Slides:



Advertisements
Similar presentations
Dale Roberts Basic I/O – scanf() CSCI 230 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Department of.
Advertisements

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.
41 A Depth Program #include int main(void) { int inches, feet, fathoms; //declarations fathoms = 7; feet = 6 * fathoms; inches = 12 * feet; printf(“Wreck.
Differences between Java and C CS-2303, C-Term Differences between Java and C CS-2303, System Programming Concepts (Slides include materials from.
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.
 2007 Pearson Education, Inc. All rights reserved C Formatted Input/Output.
1 CSE1301 Computer Programming: Lecture 9 Input/Output.
Conditionals, Loops, and Other Statements CS-2301 D-term Conditionals, Loops, and Other Kinds of Statements CS-2301 System Programming C-term 2009.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf.
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",
Conditionals, Loops, and Other Statements CS-2301, B-Term Conditionals, Loops, and Other Kinds of Statements CS-2301, System Programming for Non-Majors.
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(,,,..., );
 2007 Pearson Education, Inc. All rights reserved C Formatted Input/Output.
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 9 Formatted Input/Output Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
EPSII 59:006 Spring Introduction In this lecture  Formatted Input/Output scanf and printf  Streams (input and output) gets, puts, getchar, putchar.
Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf 9.4Printing Integers 9.5Printing Floating-Point.
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.
Chapter-4 Managing input and Output operation.  Reading, processing and writing of data are three essential functions of a computer program.  Most programs.
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.
Files A collection of related data treated as a unit. Two types Text
CCSA 221 Programming in C INPUT AND OUTPUT OPERATIONS IN C – PART 1 1.
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
Jonathan C.L. Liu, Ph.D. CISE Department University of Florida, USA
Input/output.
TMF1414 Introduction to Programming
Unit-4, Chapter-2 Managing Input and Output Operations
File Access (7.5) CSE 2031 Fall July 2018.
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.
Chapter 08- printf and scanf
Formatted Input/Output
Programming in C Input / Output.
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.
Formatted Input/Output
Chapter 9 - Formatted Input/Output
Programming Assignment #1 12-Month Calendar—
Differences between Java and C
Programming in C Input / Output.
Formatted Input/Output
Formatted Input/Output
Introduction to C EECS May 2019.
CS 1054 Introduction to Programming in Java
Introduction to C CSE 2031 Fall /15/2019 8:26 AM.
Presentation transcript:

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 from The C Programming Language, 2 nd edition, by Kernighan and Ritchie and from C: How to Program, 5 th and 6 th editions, by Deitel and Deitel)

Display a 12-Month Calendar CS-2301 D-term Display a 12-Month Calendar Prompt user for day of week of January 1 0 = Sunday 1 = Monday … 6 = Saturday Prompt user whether leap year or not Print calendar for twelve months

Display a 12-Month Calendar CS-2301 D-term Sample Output (fragment) January Sun Mon Tue Wed Thu Fri Sat February Sun Mon Tue Wed Thu Fri Sat … Note justification – right justified under day of week Two spaces between days

Display a 12-Month Calendar CS-2301 D-term Implementation Need to use loop statements for loop while loop Nested loops Need to use conditional statements if-else statement switch and break statements

Display a 12-Month Calendar CS-2301 D-term 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!

Display a 12-Month Calendar CS-2301 D-term More on 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:– Begins with '%' character Describes how to print one argument ith conversion specifier in string says how to print arg i Resulting string printed on stdout Returns number of characters printed!

Display a 12-Month Calendar CS-2301 D-term printf() (continued) %d, %i — decimal number %u — unsigned decimal number %c — character %s — string %f — floating point number e.g., %e, E — floating point number e.g., e+8 or E+8 % — a single ‘%’ character See textbook for full list (pp 154, 244)

Display a 12-Month Calendar CS-2301 D-term printf() Optional Controls %6.4f ^ – 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

Display a 12-Month Calendar CS-2301 D-term printf() Examples int j = 24; float twoPi = 2 * pi; printf("j=%d, k=%f\n", j, twoPi ); Output j=24, k= Return from printf() = 16 printf("%4d %4d %4d %6d", 1, 10, 100, 1000); Output

Display a 12-Month Calendar CS-2301 D-term 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 string or when no match is found

Display a 12-Month Calendar CS-2301 D-term scanf() Examples int i; double x; char c; scanf("%d%f%c", &i, &x, &c); Looks first for an integer Skips white space Looks next for a floating point Skips white space Looks next for a single character Does not skip white space; returns the first character it finds

Display a 12-Month Calendar CS-2301 D-term 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

Display a 12-Month Calendar CS-2301 D-term 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 Must specify “ h ” or “ l ” indicating short or long integer, float vs. double

Display a 12-Month Calendar CS-2301 D-term Questions on Assignment?