Write a program to calculate yearly depreciation of the value of an item is given by Dep = (purchase price - salvage value ) / years of service.

Slides:



Advertisements
Similar presentations
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 9 Strings.
Advertisements

Chapter 7 Strings F To process strings using the String class, the StringBuffer class, and the StringTokenizer class. F To use the String class to process.
Chapter 7 Strings F Processing strings using the String class, the StringBuffer class, and the StringTokenizer class. F Use the String class to process.
START DEFINITIONS values (3) N1 = (8, 1,-9) i N1 average N3,2 sum N2 = 0 temp N1 Do not guess or assume any values! Follow the values of the variables.
Strings and Arrays The objectives of this chapter are:  To discuss the String class and some of its methods  To discuss the creation and use of Arrays.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
1 CS 105 Lecture 8 Strings; Input Failure Mon, Mar 7, 2011, 3:39 pm.
J.43 ARRAYS  A Java array is an Object that holds an ordered collection of elements.  Components of an array can be primitive types or may reference.
Some basic I/O.
An intro to programming The basic nitty-gritty that’ll make you scratch your head and say, “This is programming?”
Introduction to Java A lab course by Dr. Junaid Ahmed Zubairi SUNY Fredonia.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 4 Control Structures I: Selection.
Sanjay Goel, School of Business, University at Albany, SUNY 1 MSI 692: Special Topics in Information Technology Lecture 4: Strings & Arrays Sanjay Goel.
COMP 14: Primitive Data and Objects May 24, 2000 Nick Vallidis.
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
C#: Statements and Methods Based on slides by Joe Hummel.
Reading and Writing to the Console Svetlin Nakov Telerik Corporation
1.  Collections are data structures that holds data in different ways for flexible operations  C# Collection classes are defined as part of the ◦ System.Collections.
Presented by: Mojtaba Khezrian. Agenda Object Creation Object Storage More on Arrays Parameter Passing For Each VarArgs Spring 2014Sharif University of.
BİL527 – Bilgisayar Programlama I Strings 1. Contents More on Variables – Type Conversions – Enumerations – Structs – Arrays – String Operations 2.
C# B 1 CSC 298 Writing a C# application. C# B 2 A first C# application // Display Hello, world on the screen public class HelloWorld { public static void.
Mastering Char to ASCII AND DOING MORE RELATED STRING MANIPULATION Why VB.Net ?  The Language resembles Pseudocode - good for teaching and learning fundamentals.
INPUT/OUTPUT STATEMENT ADDITION SLIDES. Console.ReadLine() – Use to get the input (String) from user Convert string to other data type – int.Parse() 
CS0004: Introduction to Programming Variables – Strings.
Chapter 4: Control Structures I J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition Second.
1 Lecture # 4. * An array is a group of contiguous or related data items that share a common name. * Each value is stored at a specific position * Position.
CSE 131 Computer Science 1 Module 1: (basics of Java)
Methods, Arrays, Lists, Dictionaries, Strings, Classes and Objects
VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Arrays.
Chapter 7 Strings F Processing strings using the String class, the StringBuffer class, and the StringTokenizer class. F Use the String class to process.
1 st Semester Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
Peyman Dodangeh Sharif University of Technology Fall 2013.
 Learn about control structures  Examine relational and logical operators  Explore how to form and evaluate logical (Boolean) expressions  Learn how.
Java Basics.  To checkout, use: svn co scb07f12/UTORid  Before starting coding always use: svn update.
Control Structures (B) Topics to cover here: Sequencing in C++ language.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 8: User-Defined Simple Data Types, Namespaces, and the string Type.
ECE 122 Feb. 1, Introduction to Eclipse Java Statements Declaration Assignment Method calls.
CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX.
1 The String Class F Constructing a String: F Obtaining String length and Retrieving Individual Characters in a string F String Concatenation (concat)
Introduction Chapter 1 8/31 & 9/1 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
Vladimir Misic: Characters and Strings1Tuesday, 9:39 AM Characters and Strings.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 4 Control Structures I: Selection.
Review for Final Exam. Contents 5 questions (20 points each) + 1 bonus question (20 points) – Basic concepts in Chapters 1-4 – Chapters 5-9 – Bonus: Chapter.
Object Oriented Programming (OOP) LAB # 1 TA. Maram & TA. Mubaraka TA. Kholood & TA. Aamal.
Text Files and String Processing
Peyman Dodangeh Sharif University of Technology Spring 2014.
Arrays-. An array is a way to hold more than one value at a time. It's like a list of items.
Computer Programming 2 Lab (1) I.Fatimah Alzahrani.
1 Unit-2 Arrays, Strings and Collections. 2 Arrays - Introduction An array is a group of contiguous or related data items that share a common name. Used.
In C programming, one of the frequently arising problem is to handle similar types of data. For example: If the user want to store marks of 100 students.
SEQUENTIAL AND OBJECT ORIENTED PROGRAMMING Arrays.
Chapter 5: Arrays in Java. The objectives of this chapter are:  1. To discuss the creation and use of Arrays.   2. To continue to use the String class.
Data Types References:  Data Type:  In computer science and computer programming, a data type or simply type is a.
Array. Array is a group of data of the same type. Array elements have a common name –The array as a whole is referenced through the common name Individual.
Exception and Exception Handling. Exception An abnormal event that is likely to happen during program is execution Computer could run out of memory Calling.
1 Handling Errors and Exceptions Chapter 6. 2 Objectives You will be able to: 1. Use the try, catch, and finally statements to handle exceptions. 2. Raise.
Chapter 4: Control Structures I J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition Second.
Midterm preview.
using System; namespace Demo01 { class Program
C# Arrays.
C# Programming Arrays in C# Declaring Arrays of Different Types Initializing Array Accessing Array Elements Creating User Interfaces Using Windows Standards.
Section 3.2c Strings and Method Signatures
Review for Final Exam.
Review for Final Exam.
CS1110 Today: collections.
Presentation transcript:

Write a program to calculate yearly depreciation of the value of an item is given by Dep = (purchase price - salvage value ) / years of service

1 121 12321 1234321

110 120 130 140 150…………………………190 110 121 120 132 130 143 140 154 . 190

DateTime

using System; class Unary { public static void Main() { //System.DateTime moment = new System.DateTime(1999, 1, 13, 3, 57, 32, 11); //Console.WriteLine(System.DateTime.Now); System.DateTime moment = System.DateTime.Now; // Year gets 1999. int year = moment.Year; // Month gets 1 (January). int month = moment.Month; // Day gets 13. int day = moment.Day; // Hour gets 3. int hour = moment.Hour; // Minute gets 57. int minute = moment.Minute; // Second gets 32. int second = moment.Second; // Millisecond gets 11. int millisecond = moment.Millisecond; // DateTime.Parse(" "); Console.WriteLine(day + " - " + month + " - " + year); }}

Ask the user for their birthday Ask the user for their birthday.  It will probably easiest to ask year, then month, then day rather than parsing a combined string reliably. Calculate the age of the user. Check to see if the age of the user is impossible.  For example, if the user is not yet born, output an error message.  If the user claims to be 135 years old, then let them know that's not possible. Output the age of the user to the console. If it is the user's birthday, output a nice message. Compute the user's astrological sign according to both the Western (sun sign) and Chinese astrological systems.  If you are not familiar with these astrological systems, look them up on the web. Output the computed signs to the console.  Optionally output additional information (e.g. horoscope of the day) about the user based on their sign.

String handling

namespace ConsoleApplication4 { class Program static void Main(string[] args) string str1 = "hi how r u?"; string str2 = "hi how r u"; string strup, strLow; int res, idx; Console.WriteLine(str1); Console.WriteLine("len == " + str1.Length); strLow = str1.ToLower(); strup = str1.ToUpper(); Console.WriteLine("lower == " + strLow); Console.WriteLine("upper == " + strup); Console.WriteLine("one character at time"); for (int i = 0; i < str2.Length; i++) Console.Write(str2[i]); Console.WriteLine("\n");

if (str1 == str2) Console. WriteLine("equals"); res = string if (str1 == str2) Console.WriteLine("equals"); res = string.Compare(str1, str2); if (res == 0) else if (res < 0) Console.WriteLine("str1 > str2"); else if (res > 0) Console.WriteLine("str2 > str11");

str2 = "one two three four one"; //char idx = str2 str2 = "one two three four one"; //char idx = str2.IndexOf("t"); Console.WriteLine("first idx" + idx); idx = str2.LastIndexOf("o"); Console.WriteLine("last idx" + idx); //string idx = str2.IndexOf("two",StringComparison.Ordinal); idx = str2.LastIndexOf("one",StringComparison.Ordinal);

1.The string class contains several methods that operates on string . 2.Some methods takes parameter of type String.Comparision. 3.This is enumeration type that defines how comparison involving string is conducted. Strings can be compared by two ways based on binary values called ordinal comparison - StringComparision.Ordinal dictionary order - culture sensitive - StringComparision.CurrentCulture

//concatenation str3 = str1 + str2; Console //concatenation str3 = str1 + str2; Console.WriteLine(str3); //array of string string[] str = {"this" , "is" , "a" , "test."}; str[1] = "was"; str[3] = "test, too !"; for (int i = 0; i < str.Length; i++) Console.WriteLine(str[i] + "\n"); }

Strings are immutable--the contents of a string object cannot be changed after the object is created, although the syntax makes it appear as if you can do this. For example, when you write this code, the compiler actually creates a new string object to hold the new sequence of characters, and that new object is assigned to b. The string "h" is then eligible for garbage collection. string b = "h" b = b + "ello"

String is immutable i.e. Strings cannot be altered. When you alter a string (by adding to it for example), you are actually creating a new string. But StringBuilder is not immutable (Mutable) so if u have to alter a string many times, such as mutliple concatenations then use StringBuilder.

C# offers a class called StringBuilder which is in System C# offers a class called StringBuilder which is in System.Text namespace. StringBuilder s;

write a program for display an integer value using words eg 19 - one nine

Handling arrays

int n = arrayname.Length;

using System; using System using System; using System.Collections; namespace ConsoleApplication1 { class Program { static void Main(string[] args) int[] numbers = { 4, 3, 8, 0, 5 }; Array.Sort(numbers); foreach(int i in numbers) Console.WriteLine(i); Console.ReadLine(); }

Multidimensional arrays come in two flavors with C#: Rectangular arrays and jagged arrays. The difference is that with rectangular arrays, all the dimensions have to be the same size, hence the name rectangular. A jagged array can have dimensions of various sizes.