Advanced Computer Programming°L255/icerik/Week1.pdf · programming languages such as Java, Pascal,...
Transcript of Advanced Computer Programming°L255/icerik/Week1.pdf · programming languages such as Java, Pascal,...
COURSE POLICY
Advanced Computer Programming
Grading:Midtem1-2 : %15 Projects : %15 Quiz : %15 Final : %40
SYLLABUS
Advanced Computer Programming
Introduction to Programming
Introduction to Microsoft Visual Studio
Data types and expressions
Conditions and loops
Arrays and Collections
Classes and Functions
File I/O operations
BOOK: C# 2010 for programmers (Fourth Edition) Paul Deitel and Harvey Ditel
COMPUTER
Advanced Computer Programming
A computer is a complex system consisting of many different components. But at the heart—or the brain, if you want—of the computer is a single component that does the actual computing. This is the Central Processing Unit, or CPU.
A program is simply a list of unambiguous instructions meant to befollowed mechanically by a computer. A computer is built to carryout instructions that are written in a very simple type of languagecalled machine language. Each type of computer has its ownmachine language, and the computer can directly execute a programonly if the program is expressed in that language.
When the CPU executes a program, that program is stored in thecomputer’s main memory (also called the RAM or random accessmemory). In addition to the program, memory can also hold datathat is being used or processed by the program.
COMPUTER
Advanced Computer Programming
Machine language consists of very simple instructions that can be executed directlyby the CPU of a computer. Almost all programs, though, are written in high-levelprogramming languages such as Java, Pascal, or C++. A program written in a high-level language cannot be run directly on any computer. First, it has to be translatedinto machine language. This translation can be done by a program called a compiler.A compiler takes a high-level-language program and translates it into an executablemachine-language program.
A compiler takes a high-level-language program and translates it into an executablemachine-language program. Once the translation is done, the machine-languageprogram can be run any number of times, but of course it can only be run on onetype of computer (since each type of computer has its own individual machinelanguage).
CPU and MAIN MEMORY
Advanced Computer Programming
Secondary Memory Devices
Copyright © 2012 Pearson Education, Inc.
BINARY NUMBERS
Advanced Computer Programming
Once information has been digitized, it is represented and stored in
memory using the binary number system
A single binary digit (0 or 1) is called a bit(unit symbol is b)
A byte is 8 bits (unit symbol is B)
Devices that store and move information are cheaper and more reliable if
they have to represent only two states
A single bit can represent two possible states, like a light bulb that is
either on (1) or off (0)
Permutations of bits are used to store values
BINARY NUMBERS
Advanced Computer Programming
1 bit 2 bits 3 bits 4 bits
0 00 000 0000 1000
1 01 001 0001 1001
10 010 0010 1010
11 011 0011 1011
100 0100 1100
101 0101 1101
110 0110 1110
111 0111 1111
BINARY NUMBERS
Advanced Computer Programming
In decimal numbers we use 10 digits (0-9) – base 10. Each digit used in a
number has a place value
Example: 8427 = 8*103 + 4*102 + 2*101 + 7*100 = 8000 + 400 +
20 + 7 = 8427
In binary numbers we use 2 digits (0-1). Each digit in a binary number has a
place value but the base is now 2
Example: 1101=1*23 +1*22 +0*21 +1*20 =8+4+0+1 = 13
Using the above definition you convert from binary to decimal.
BINARY NUMBERS
Advanced Computer Programming
Storing Information
10011010
Copyright © 2012 Pearson Education, Inc.
COMPUTER ARCHITECTURE
Advanced Computer Programming
Computer Architecture
Copyright © 2012 Pearson Education, Inc.
OVERVIEW
Coding - Programming
– Coding is what makes it possible for us to create computer software, apps andwebsites.
– Programming is a core activity in the process of performing tasks or solvingproblems with the aid of a computer. An idealized picture is:
[problem or task specification] - COMPUTER - [solution or completed task]
– A program is a set of instructions that tell the computer to do various things;sometimes the instruction it has to perform depends on what happened when itperformed a previous instruction.
– Programming isn't something that you can learn in an hour. But you can begin toappreciate it.
Advanced Computer Programming
OVERVIEW
C, C++, Objective-C and Java
– The C programming language was developed in the early 1970s. C first gained widespreadrecognition as the development language of the UNIX operating system. C is a hardware-independent language, and, with careful design, it’s possible to write C programs that areportable to most computers.
– C++, developed in the early 1980s, provides several features that “spruce up” the C language,and, more importantly, capabilities for object-oriented programming (OOP).
– The Objective-C programming language, also developed in the early 1980s, added capabilitiesfor object-oriented programming (OOP) to the C programming language. It eventually becamethe software development language for Apple’s Macintosh.
– Microprocessors are having a profound impact in intelligent consumer electronic devices.Recognizing this, Sun Microsystems in 1991 funded an internal corporate research project thatresulted in the development of a C++-based language, which Sun eventually called Java.
Advanced Computer Programming
OVERVIEW
C#
– In 2000, Microsoft announced the C# (pronounced “C-Sharp”) programming language createdspecifically for the .NET platform. C# has roots in C, C++ and Java. Like Visual Basic, C# isobject oriented and has access to the powerful .NET Framework Class Library—a vast collectionof prebuilt components, enabling you to develop applications quickly.
–C# (pronounced "C sharp") is a simple, modern, object-oriented, and type-safe programminglanguage. It will immediately be familiar to C and C++ programmers. C# combines the highproductivity of Rapid Application Development (RAD) languages and the raw power of C++.
– In 2000, Microsoft announced its .NET initiative (www.microsoft.com/net), a broad new visionfor using the Internet and the web in the development, engineering, distribution and use ofsoftware. Rather than forcing developers to use a single programming language, the .NETinitiative permits developers to create .NET applications in any .NET- compatible language (suchas C#, Visual Basic, and others). Part of the initiative includes Microsoft’s ASP.NET technology,which allows you to create web applications.
– The .NET Framework is at the heart of Microsoft’s .NET strategy. This framework executesapplications, includes the .NET Framework Class Library and provides many other programmingcapabilities that you’ll use to build C# applications.
Advanced Computer Programming
PROGRAMMING
Advanced Computer Programming
Problem determination
Analysis
Algorithm
Writing code
Testing
PROBLEM DETERMINATION
Advanced Computer Programming
Define what to do
Field investigation
Other arguments
ANALYSIS
Advanced Computer Programming
Program inputs and outputs
Variables that are going to be in the program
Data flow within the program
CODING
Advanced Computer Programming
Converting the algorithm to a programming language
Realization of the program
Fixing coding errors and bugs
TESTING
Advanced Computer Programming
Checking whether program produces expected
outputs to given inputs.
Fixing logical errors
Step-by-step investigation of program execution with
using a special program “Debugger”
PROBLEM DETERMINATION
Advanced Computer Programming
Determine the phases to make an omelet.
What kind of problems that we may encounter.
What kind of help could we get.
ANALYSIS
Advanced Computer Programming
Inputs
Egg, oil, salt, spices
Variables
Oven, pan, fork, plate
ALGORITHM
Advanced Computer Programming
Turn on oven
Put the pan to the oven
Pour some oil to the pan
Break eggs in to the pan
Add salt
Mix
Add spices
Mix
C# - C++ - Java
Defining variables
C#:
int x = 0;
C++ :
int x = 0;
Java :
int x = 0;
For Loop
C#:
for(int i = 0;i<10;i++)
console.WriteLine(“{0}”,i);
C++ :
for(int i = 0;i<10;i++)
printf(“%d”,i);
Java :
for(int i = 0;i<10;i++)
system.out.println(i);
if-else
C#:
if(nCount<Max)
nCount++;
else
total += nCount;
C++ :
if(nCount<Max)
nCount++;
else
total += nCount;
Java :
if(nCount<Max)
nCount++;
else
total += nCount;
VS .Net 2012
A Microsoft product
IDE (Integrated Development Environment)
Editor + Compiler + Debugger
A program which creates other programs
Advanced Computer Programming
C# (C Sharp)
• A compiler turns the program that you write into an executable that your computer canactually understand and run.
• A C# program is a collection of commands, which tell the computer to do "something".
• This collection of commands is usually called C# source code, source code or just code.
• Every program in C# has one function, always named main, that is always called when yourprogram first executes.
• From main, you can also call other functions whether they are written by us or, as mentionedearlier, provided by the compiler.
• Following the include is the statement, "using namespace std;". This line tells the compiler touse a group of functions that are part of the standard library (std).
• The next important line is int main(). This line tells the compiler that there is a functionnamed main, and that the function returns an integer, hence int. The "curly braces" ({ and })signal the beginning and end of functions and other code blocks. You can think of them asmeaning BEGIN and END.
Advanced Computer Programming
VS .Net 2012
Advanced Computer Programming
Program window
Previously created projects
Creating a new project
Start page
VS .Net 2012
Advanced Computer Programming
Programming Language
Project Type
Name of the program
Directory in which our project will be created
First Program
Advanced Computer Programming
Each program requires three important steps to do work. It is Input, Process and Output.It is the basic concept of almost all the programming language. It is also known as I-P-Ocycle. The program requires some input from the user. Next, the program processes theinput with programming language and finally shows the output.
First Program
Advanced Computer Programming
References
It is used for including C# class library. C# has huge collection of classes and objects.If you want to use those classes then you will have to include their library name in your program.
First Program
Advanced Computer Programming
References
Namespace
Class
Main
A C# console application must contain a Main method, in which control starts and ends. The Main method is where you create objects and execute other methods.
static void Main(string[] args){
//...}
or
static int Main(string[] args){
//...return 0;
}
First Program
Advanced Computer Programming
Every opening bracketshould have an closing one.
We write ourcodes withinthese brackets
First Program
Advanced Computer Programming
Main
Print to screen
Print current date and time to screen
“;” Semicolon: end of statement
Comments
Building the Project
Advanced Computer Programming
Hint: Just press F6 key to build a project.
Build menu item
Executing the Program
Advanced Computer Programming
Hint: Just press F5 key to execute a program.
“Run” menu item
LINKS
• http://mfidan.home.anadolu.edu.tr
• http://www.cprogramming.com
• http://msdn.microsoft.com/en-us/vstudio/
• https://www.acikakademi.com/portal/default.aspx
• Smartphone Application: Learn C# (by Sololearn Inc.) (Available for both Android and Apple)
Advanced Computer Programming