Exercise 1 Introduction to C# CIS-2320. 2 Code the C# program to prompt the user to key in 12 integer values from the keyboard. If a value containing.

Slides:



Advertisements
Similar presentations
Computer Programming Lab(7).
Advertisements

Exercise (1).
L2:CSC © Dr. Basheer M. Nasef Lecture #2 By Dr. Basheer M. Nasef.
CS102--Object Oriented Programming Discussion 2: (programming strategy in java) – Two types of tasks – The use of arrays Copyright © 2008 Xiaoyan Li.
Registers and Ranges. Register – Compared to a Calculator If there are only 9 digits available on display how long can the number displayed be? ANS: 9.
Overview Reference parameters Documenting functions A game of craps. Design, code, test and document.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Java review and more. Class Header  Public class Welcome  Case sensitive  Body of the class must be enclosed by braces.
Mathematical Operators  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming in.
Overview creating your own functions calling your own functions.
1 Lab Session-3 CSIT221 Spring 2003 b Group Worksheet 3 Exercise (Demo Required) b No new lab demo will be assigned to allow you to focus on HW#1.
Variables, Data Types, & Arithmetic Expressions CSC 1401: Introduction to Programming with Java Lecture 3 Wanda M. Kunkle.
1 10/9/06CS150 Introduction to Computer Science 1 for Loops.
1 Lab Session-3 CSIT 121 Spring’05 Division rules Operator precedence rules Lab Exercise.
Java vs. You.
COMP 110 Introduction to Programming Mr. Joshua Stough September 10, 2007.
1 Lab Session-7 CSIT-121 Fall Introducing Structured Choice 4 The do~While Loop 4 Lab Exercises.
Practice for Midterm 1. Practice problems These slides have six programming problems for in-class practice There are an additional seven programming problems.
Basic Input/Output and Variables Ethan Cerami New York
LAB 10.
Computer Programming Lab(4).
Computer Programming Lab(5).
Input/Output  Input/Output operations are performed using input/output functions  Common input/output functions are provided as part of C’s standard.
1 Project 5: Median. 2 The median of a collection of numbers is the member for which there are an equal number less than or equal and greater than or.
Introduction to Classes and Objects (Through Ch 5) Dr. John P. Abraham Professor UTPA.
E0001 Computers in Engineering
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Mastering Char to ASCII AND DOING MORE RELATED STRING MANIPULATION Why VB.Net ?  The Language resembles Pseudocode - good for teaching and learning fundamentals.
Java Programming: From the Ground Up
1 Introduction to Java Brief history of Java Sample Java Program Compiling & Executing Reading: => Section 1.1.
SAT Review 1.Which is the equation of a line that passes through the pt (7, - 1) and is to y + 2x = 1. A. y = 2x – 15 B. y = –2x + 13 C. D. 2.Line p is.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
More While Loop Examples CS303E: Elements of Computers and Programming.
Lecture-5 Miscellaneous. Random Numbers Can use ‘rand()’ function declared in the stdlib.h header file The seed for random number generation can be set.
Type Conversions Implicit Conversion Explicit Conversion.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
CHAPTER 7 DATA INPUT OUTPUT Prepared by: Lec. Ghader R. Kurdi.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
EXERCISES for ALGORITHMS WRITING
Count and add list of numbers From user input and from file.
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
Chapter 4 Practice cont.. Practice with nested loops 1.What will be the output of the following program segment: 1.for (int i = 1; i
Lecture 5: Stopping with a Sentinel. Using a Sentinel Problem Develop a class-averaging program that will process an arbitrary number of grades each time.
CS110 Programming Language I Lab 4: Control Statements I Computer Science Department Spring 2014.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Exercise 2 Introduction to C# CIS Create a class called Employee that contains the following private instance variables: Social Securitystring.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Data Validation while loops. Data validation Programs get input data from different sources All data should be ‘validated’ before the program tries to.
Agenda Perform Quiz #1 (20 minutes) Loops –Introduction / Purpose –while loops Structure / Examples involving a while loop –do/while loops Structure /
Programming Fundamentals I Java Programming Spring 2009 Instructor: Xuan Tung Hoang TA: Tran Minh Trung Lab 03.
Chapter 8 Arrays. A First Book of ANSI C, Fourth Edition2 Introduction Atomic variable: variable whose value cannot be further subdivided into a built-in.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA CSC141 Computer Science I 2/4/20161.
Data Types and Conversions, Input from the Keyboard If you can't write it down in English, you can't code it. -- Peter Halpern If you lie to the computer,
Martin T. Press.  Main Method and Class Name  Printing To Screen  Scanner.
Integrated Mathematics Compare & Order Real Numbers.
CS 112 Introduction to Programming Loop Patterns: break; Fencepost Yang (Richard) Yang Computer Science Department Yale University 308A Watson, Phone:
CPSC 233 Tutorial 5 February 2 th /3 th, Java Loop Statements A portion of a program that repeats a statement or a group of statements is called.
CHAPTER 6 ARRAYS IN C 1 st semester King Saud University College of Applied studies and Community Service Csc 1101 F. Alakeel.
1 Input (Read) Statement. Variable Declaration (Definition) Initialization Assignment Displaying variables: using cout statement Reading variables from.
Data Types and Conversions, Input from the Keyboard
2.5 Another Java Application: Adding Integers
Exercise Evaluate
Maha AlSaif Maryam AlQattan
INPUT STATEMENTS GC 201.
Control Statement Examples
Suppose I want to add all the even integers from 1 to 100 (inclusive)
Every number has its place!
CHAPTER 6 Testing and Debugging.
Presentation transcript:

Exercise 1 Introduction to C# CIS-2320

2 Code the C# program to prompt the user to key in 12 integer values from the keyboard. If a value containing invalid characters is detected, display an error message, and skip the value. If a negative value is detected, display an error message, and skip the value. If a value greater than 3 digits (999) is detected, display an error message, and skip the value. When 12 valid values have been entered:   Display the sum of the values entered   Display the largest and smallest value entered   Display the average of the values entered to the nearest 2 decimal places

3 Sample program output: Enter a 1 to 3 digit number: 345 Enter a 1 to 3 digit number: 55 Enter a 1 to 3 digit number: 999 Enter a 1 to 3 digit number: -44 Error: Value entered is negative Enter a 1 to 3 digit number: Error: Value entered is greater than 999 Enter a 1 to 3 digit number: 1 Enter a 1 to 3 digit number: abc Error: Data entered contains invalid characters Enter a 1 to 3 digit number: 4 Enter a 1 to 3 digit number: 77 Enter a 1 to 3 digit number: 444 Enter a 1 to 3 digit number: -5 Error: Value entered is negative Enter a 1 to 3 digit number: 789 Enter a 1 to 3 digit number: 34 Enter a 1 to 3 digit number: 500 Enter a 1 to 3 digit number: 22 Enter a 1 to 3 digit number: 56 Sum of all values.....: 3326 Largest value is......: 999 Smallest value is.....: 1 Average of the values.:

4 Extra Points: 2 points: Create a class with all processing code in the constructor, then create an instance of this class in Main() calling it's constructor. Also create a DisplayTotals() method to display the total lines. Call this method from Main(). This class should be in a separate.cs file. Main() should look as follows: static void Main() { xxxxx ob = new xxxxx(); ob.DisplayTotals(); } 2 points: Display all error messages using the MessageBox class.