Object oriented lab /second year / review/lecturer: yasmin maki

Similar documents
CALCULATOR APPLICATION

CSIS 1624 CLASS TEST 6

if (say==0) { k.commandtext = "Insert into kullanici(k_adi,sifre) values('" + textbox3.text + "','" + textbox4.text + "')"; k.

First start a new Windows Form Application from C# and name it Interest Calculator. We need 3 text boxes. 4 labels. 1 button

Now find the button component in the tool box. [if toolbox isn't present click VIEW on the top and click toolbox]

C# winforms gridview

You can call the project anything you like I will be calling this one project slide show.

To start we will be using visual studio Start a new C# windows form application project and name it motivational quotes viewer

The Open Core Interface SDK has to be installed on your development computer. The SDK can be downloaded at:

Class Test 4. Question 1. Use notepad to create a console application that displays a stick figure. See figure 1. Question 2

Experiment 5 : Creating a Windows application to interface with 7-Segment LED display

II. Programming Technologies

create database ABCD use ABCD create table bolumler ( bolumkodu int primary key, bolumadi varchar(20) )

Overview. Building a Web-Enabled Decision Support System. Integrating DSS in Business Curriculum. Introduction to DatabaseSupport Systems

Form Properties Window

Click on the empty form and apply the following options to the properties Windows.

Mainly three tables namely Teacher, Student and Class for small database of a school. are used. The snapshots of all three tables are shown below.

Visual Basic/C# Programming (330)

Huw Talliss Data Structures and Variables. Variables

We are going to use some graphics and found a nice little batman running GIF, off course you can use any image you want for the project.

Start Visual Studio, start a new Windows Form project under the C# language, name the project BalloonPop MooICT and click OK.

UNIT-3. Prepared by R.VINODINI 1

Main Game Code. //ok honestly im not sure, if i guess its a class ment for this page called methodtimer that //either uses the timer or set to timer..

Start Visual Studio and create a new windows form application under C# programming language. Call this project YouTube Alarm Clock.

Start Visual Studio, create a new project called Helicopter Game and press OK

The Gracefulness of the Merging Graph N ** C 4 with Dotnet Framework

} } public void getir() { DataTable dt = vt.dtgetir("select* from stok order by stokadi");

IBSDK Quick Start Tutorial for C# 2010

string spath; string sedifile = "277_005010X228.X12"; string sseffile = "277_005010X228.SemRef.EVAL0.SEF";

LISTING PROGRAM. // // TODO: Add constructor code after the InitializeComponent() call. //

This is the empty form we will be working with in this game. Look under the properties window and find the following and change them.

بسم هللا الرحمن الرحيم المحاضرة السابعة مستوى ثالث علوم حاسوب برمجة مرئية 2 )عملي ) جامعة الجزيرة محافظة اب الجمهورية اليمنية النافذة الرئيسية

pojedinačnom elementu niza se pristupa imeniza[indeks] indeks od 0 do n-1

เว บแอพล เคช น. private void Back_Click(object sender, EventArgs e) { this.webbrowser2.goback(); }

Visual Basic/C# Programming (330)

RegEx - Numbers matching. Below is a sample code to find the existence of integers within a string.

APARAT DE MASURA. Descrierea programului

Representing Recursive Relationships Using REP++ TreeView

// Specify SEF file to load. oschema = (edischema) oedidoc.loadschema(spath + sseffilename, SchemaTypeIDConstants. Schema_Standard_Exchange_Format);

Writing Your First Autodesk Revit Model Review Plug-In

Create your own Meme Maker in C#

// Specify SEF file to load. edischema oschema = oedidoc.loadschema(spath + sseffilename, SchemaTypeIDConstants. Schema_Standard_Exchange_Format);

Answer on Question# Programming, C#

Conventions in this tutorial

// Precondition: None // Postcondition: The address' name has been set to the // specified value set;

APÉNDICE J. CÓDIGO DEL ARCHIVO FORM1.CS EN LENGUAJE C# Comprende:

// Program 2 - Extra Credit // CIS // Spring // Due: 3/11/2015. // By: Andrew L. Wright. //Edited by : Ben Spalding

namespace csharp_gen277x214 { public partial class Form1 : Form { public Form1() { InitializeComponent(); }

Lab - 1. Solution : 1. // Building a Simple Console Application. class HelloCsharp. static void Main() System.Console.WriteLine ("Hello from C#.

Sub To Srt Converter. This is the source code of this program. It is made in C# with.net 2.0.

Final Exam Review April 18, 2018

Visual C#.net examples

RegEx-validate IP address. Defined below is the pattern for checking an IP address with value: String Pattern Explanation

IOSR Journal of Engineering (IOSRJEN) e-issn: , p-issn: Vol. 3, Issue 8 (August. 2013), V3 PP 25-33

C = E(p) = (p + k) mod (n) p = D(C) = (C k) mod (n)

namespace csharp_gen837x223a2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); }

namespace Gen837X222A1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); }

عنوان مقاله : خواندن و نوشتن محتوای فایل های Excel بدون استفاده ازAutomation Excel تهیه وتنظیم کننده : مرجع تخصصی برنامه نویسان

Examples. Products. W informs Controls > Products > Navigation Bar > Examples. This topic provides how -to examples, grouped by features.

Hands-On Lab. Lab: Client Object Model. Lab version: Last updated: 2/23/2011

private string sconnection = ConfigurationManager.ConnectionStrings["Development"].ConnectionString

How to create a simple ASP.NET page to create/search data on baan using baan logic from the BOBS client sample.

Unit 1 Workbook ICS3U

Savoy ActiveX Control User Guide

Computer measurement and control

Визуал програмчлал. Багш: Ж. Шинэбаяр /Маг/

FDSc in ICT. Building a Program in C#

C:\homeworks\PenAttention_v13_src\PenAttention_v13_src\PenAttention4\PenAttention\PenAttention.cs 1 using System; 2 using System.Diagnostics; 3 using

Tutorial 6 Enhancing the Inventory Application Introducing Variables, Memory Concepts and Arithmetic

Your Company Name. Tel: Fax: Microsoft Visual Studio C# Project Source Code Output

Eyes of the Dragon - XNA Part 37 Map Editor Revisited

Web Services in.net (2)

Getting Started with ComponentOne LiveLinq

Using Template Bookmarks for Automating Microsoft Word Reports

private void Form1_Load(object sender, EventArgs e) {

Lecture 8 Building an MDI Application

Engr 123 April 25, 2018 Final Exam Review. 3. Write a method which will accept a string and return the number of three-letter words in the string.

namespace spojneice { public partial class Form1 : Form { public Form1() { InitializeComponent(); }

Introduction to Visual Studio and C#

LAB 11: METHODS. CPCS The Lab Note Lab 11 Page 1. Statement Purpose:

Problem Statement. B1: average speed

Developing for Mobile Devices Lab (Part 1 of 2)

Objectives : 1) To study the typical design of a LCD module 2) To interface the digital display unit through parallel printer port using C# program.

LISTING PROGRAM. //Find the maximum and minimum values in the array int maxvalue = integers[0]; //start with first element int minvalue = integers[0];

User-Defined Controls

Classes in C# namespace classtest { public class myclass { public myclass() { } } }

Hands-On Lab (MBL04) Lab Manual Incorporating COM Objects into Your.NET Compact Framework 2.0 Application

LIGHT_P_TOGGLE, LIGHT_N_TOGGLE, BATTERY_TOGGLE, ALTERNATOR_TOGGLE, AVIONICS_TOGGLE, FLOAT_RETRACT, FLOAT_EXTEND }

Bachelor s Thesis: Building Web Application for Mahabad University Graduate Affairs Afsaneh Nezami Savojbolaghi

Duhok Polytechnic University Amedi Technical Institute/ IT Dept. Halkawt Rajab Hussain

Name: Username: I. 20. Section: II. p p p III. p p p p Total 100. CMSC 202 Section 06 Fall 2015

NI USB-TC01 Thermocouple Measurement Device

Teacher Training Solutions

Problem Statement. A1: being lapped on the track

LAMPIRAN A : LISTING PROGRAM

private string sconnection = ConfigurationManager.ConnectionStrings["Development"].ConnectionString

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

Functions. Lab 4. Introduction: A function : is a collection of statements that are grouped together to perform an operation.

Chapter 12. Tool Strips, Status Strips, and Splitters

CMSC 202 Midterm Exam 1 Fall 2015

Transcription:

1) Examples of method (function): Note: the declaration of any method is : <access modifier> <return type> method name ( parameters list ).. Method body.. Access modifier : public,protected, private. Return type : int double,decimal,char,string,bool ( depending on the return variable type ) or void. Method name : a string series of characters. Parameters list : (variable type variable name1, variable type variable name2,..etc) Method body : the process of the method maybe one or more lines of instructions. Example(1): Create a function FindMax that takes two integer values and returns the larger of the two. It has public access specifier, so it can be accessed from outside the class using an instance of the class. Solution: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication1 public partial class Form1 : Form public Form1() InitializeComponent(); public int FindMax(int num1, int num2) /* local variable declaration */ int result; if (num1 > num2) result = num1; else result = num2; return result; 1

private void button1_click(object sender, EventArgs e) int num1, num2, result; num1 = Convert.ToInt32(textBox1.Text); num2 = Convert.ToInt32(textBox2.Text); result = FindMax(num1, num2); label4.text = result.tostring(); Output : Example (2): Create a windows form C# project that read a student info ( name(string) Address( string ),age ( double) sex( char), marks ( m1,m2,m2,m3) ( double) Then display the result as ( fail/pass), and the average if the students four marks greater than 50. Solution : using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace studentwithoutmethod public partial class Form1 : Form public Form1() InitializeComponent(); private void Form1_Load(object sender, EventArgs e) 2

private void button1_click(object sender, EventArgs e) string name,address,result; char sex; double age,m1,m2,m3,m4,average; //read name name = textbox1.text; //read age as a string then convert to double age = Convert.ToDouble(textBox2.Text); //read address address = textbox3.text; //read sex as striing then convert charcter (f=female m=mail) sex = Convert.ToChar(textBox4.Text); //read mark for four subjects m1 = Convert.ToDouble(textBox5.Text); m2 = Convert.ToDouble(textBox6.Text); m3 = Convert.ToDouble(textBox7.Text); m4 = Convert.ToDouble(textBox8.Text); // check if the student pass or fail if ((m1 > 50) && (m2 > 50) && (m3 > 50) && (m4 > 50)) result = "pass"; average=(m1+m2+m3+m4)/4; textbox10.text=convert.tostring(average); else result="fail"; // display the result textbox9.text =result; private void textbox9_textchanged(object sender, EventArgs e) Output : 1) if the student pass : 3

2)if the student fail : re-write the program : 1)read the values from the program. 2) add method that calculate the average if the student pass the exam. public double calc_average(double m1, double m2, double m3, double m4) return (m1 + m2 + m3+m4) / 4; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace studentwithoutmethod public partial class Form1 : Form public Form1() InitializeComponent(); private void Form1_Load(object sender, EventArgs e) 4

public double calc_average(double m1, double m2, double m3, double m4) return (m1 + m2 + m3+m4) / 4; private void button1_click(object sender, EventArgs e) string name,address,result; char sex; double age,m1,m2,m3,m4,average; //read name name = textbox1.text; //read age as astring then convert todouble age = Convert.ToDouble(textBox2.Text); //read address address = textbox3.text; //read sex as striing conert to charcter (f=female m=mail) sex = Convert.ToChar(textBox4.Text); //read mark for four subjects m1 = Convert.ToDouble(textBox5.Text); m2 = Convert.ToDouble(textBox6.Text); m3 = Convert.ToDouble(textBox7.Text); m4 = Convert.ToDouble(textBox8.Text); // check if the student passor fail if ((m1 >= 50) && (m2 >= 50) && (m3 >= 50) && (m4 >= 50)) result = "pass"; average = calc_average(m1, m2, m3, m4); //average = Average_method(m1, m2,m3,m4); textbox10.text=convert.tostring(average); else result="fail"; // display the result textbox9.text =result; Output: private void textbox9_textchanged(object sender, EventArgs e) 5

Example ( 3) : Method to Calculate the Sum of Prices of Books can use arrays as parameters for a certain method (int[], double[], string[], ). Imagine we are in a bookstore and we want to calculate the amount of money we must pay for all the books we bought. We will create a method that gets the prices of all the books as an array of type decimal[], and then returns the total amount we must pay: public decimal calculate_amountforbooks(decimal[] prices) decimal totalamount = 0; foreach (decimal singlebookprice in prices) totalamount += singlebookprice; return totalamount; solution: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace booksprices 6

public partial class Form1 : Form public Form1() InitializeComponent(); public decimal calculate_amountforbooks(decimal[] prices) decimal totalamount = 0; foreach (decimal singlebookprice in prices) totalamount += singlebookprice; return totalamount; private void button1_click(object sender, EventArgs e) decimal[] pr = 20.5m, 30.60m,1000m; decimal total = calculate_amountforbooks(pr); MessageBox.Show("The total amount for all books is:" +total); Output : example ( 4 ) : overloading 7

Note: When in more than one method is declared and its name is the same but their signatures differ by their parameters list (count of the method s parameters,types of parameters or the way they are arranged), we say that there are different variations / overloads of that method (method overloading). As an example, let s assume that we have to write a program that draws letters and digits to the screen. C# language allows us to create variations of the same method Display( ), called overloads. The method below gets combinations of different parameters, depending of what we want to write on the screen: public void Display(string str) // display string public void Display(int number) // display integer Example(5): Write a program that read a value and check if the value is string or number using method overloading : using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace display public partial class Form1 : Form public Form1() InitializeComponent(); 8

private void Form1_Load(object sender, EventArgs e) public void Display(string str) // display string MessageBox.Show("string "+str); public void Display(int number) // display integer MessageBox.Show("int " ); private void textbox1_textchanged(object sender, EventArgs e) int intnum; if (int.tryparse(textbox1.text, out intnum)) Display(intnum); else Display(textBox1.Text); Output : 9

Exercises 1. Create a method GetMax() with two integer (int) parameters, that returns maximal of the two numbers. 2. Write a program that reads three numbers from the text box and prints the biggest of them. Use the GetMax() method you just created. Write a test program that validates that the works correctly. 3. Write a method that returns the English name of the last digit of a given number. Example: for 512 prints "two"; for 1024 "four". 4. Write a method that finds how many times certain number can be found in a given array. Write a program to test that the method works correctly. 5. Write a method that checks whether an element, from a certain position in an array is greater than its two neighbors. Test whether the method works correctly. 6. Write a method that returns the position of the first occurrence of an element from an array, such that it is greater than its two neighbors simultaneously. Otherwise the result must be -1. 7. 7.Write a method that prints the digits of a given decimal number in a reversed order. For example 256, must be printed as 652. 8. Write a method that calculates the sum of two very positive integer numbers. The numbers are represented as array digits and the last digit (the ones) is stored in the array at index 0. Make the method work for all numbers with length up to 10,000 digits. 9. Write a method that finds the biggest element of an array. Use that method to implement sorting in descending order. 11. Write a program that solves the following tasks: - Put the digits from an integer number into a reversed order. Calculate the average of given sequence of numbers. - Solve the linear equation a * x + b = 0. Create appropriate for each of the above tasks. 10