CS111 Intro to CS-SC Lecture 3 (Fall 2019) PDF

Summary

This document is a lecture on software types and the basics of C programming. It covers various software categories, the differences between code and software, and includes questions related to this topic. It encompasses computer science concepts and is intended for introductory-level programmers.

Full Transcript

CS111 – Level 1 ( Introduction to Computer Science – General Division ) ( Introduction to Soft-Computing – Medical Informatics Program ) Lecture 3 Types of Software & the Basics of C Programs Fall 2019 (Semester 1)...

CS111 – Level 1 ( Introduction to Computer Science – General Division ) ( Introduction to Soft-Computing – Medical Informatics Program ) Lecture 3 Types of Software & the Basics of C Programs Fall 2019 (Semester 1) Week 4 Course & Lectures are based on their counterparts in the following courses: o Harvard University's CS50; An introduction to the intellectual enterprises of computer science and the art of programming, Harvard School of Engineering and Applied Sciences. o UNSW's CS1: Higher Computing, by Richard Buckland – The University of New South Wales. Programs Vs. Software 2 Software Engineering Types of Software Classification of Computer Systems Your First C Program The MAIN Function O A Statement u t The PRINTF Function Outline l i n A String Escape Sequences Preprocessor Directives e Header File The RETURN Statement Why does the MAIN function return a 0? Comments Blank-lines, Spaces, Tabs,.. etc. 2 Recap: Computer science is fundamentally problem-solving; taking some input (details about our problem) & generating some output (the solution to our problem). Information Processing is converting data (raw, unorganized facts) into information (data processed into a meaningful form). Algorithms are step-by-step instructions for solving a problem. Computer Science (Problem → Output Input (problem Solving, (problem’s definition, Information solution, data) → Processing) information.. via Algorithms 3 Recap: The four essential properties of an algorithm: ‫ ﻣﺣدد‬i. Exact: Precisely and unambiguously described, so that there remains no uncertainty. ‫ ﻣﻧﺗﮭﻲ‬ii. Terminate: The ultimate purpose of an algorithm is to solve a problem. ‫ ﻣؤﺛر‬iii. Effective: Must give the correct answer. ‫ ﻋﺎم‬iv. General: Must solve every instance of the problem. E.g., a program that computes the area of a rectangle, within the limits of the programming language and the machine. Two commonly used tools to represent algorithms: 1. Pseudocode 2. Flowcharts 4 Recap: Your first C program.. #include int main(void) { printf( “Hello, World!\n" ); return 0; } So,.... 1) What is a program? What’s the difference between code and software? What are the different types of software? 2) What are the keywords, functions, & syntax rules present in your first C program? 5 Program versus Software.. Software Types, &.. Software Engineering 6 Programs Vs. Software.. o Program; is a set of instructions telling a computer what to do. o Software; is the computer program(s) and the associated documentation. Software products may be developed for a particular customer or may be developed for a general market. 7 How to solve a problem? Software Engineering.. 1. Define the problem. 2. Analyze the problem (i.e. specifying the requirements). 3. Develop an algorithm (a method) for solving a problem (i.e. design; designing the solution). 4. Write a computer program corresponding to the algorithm (i.e. implementation). 5. Test and debug the program (i.e. testing). 6. Document everything about the program (write an explanation of how the program is designed, how it works, how it was tested, and how to use it). 8 Types of Software.. The 2 basic categories of Software are: System Software: Mainly, Operating systems that allow computers to operate; o Boots the computer and launches programs at the user’s direction. o Mostly uses a GUI “Graphical User Interface” to interact with the user via windows, icons, menus, buttons,.. etc. o E.g. Windows, Mac OS, Linux, android, etc. Application Software: Software which allows computers to carry out specific tasks related to the users; o E.g. Payroll processing, inventory control, word processing,.. etc. 9 Types of Software 10 Types of Software.. The Software also varies based on the type/category of the computer. The Six basic categories of computers are: 1) Embedded Computers. ‫زي اﻟﻐﺳﺎﻟﺔ ﻣﺛﻼ و اي ﺣﺎﺟﮫ دﯾﺟﯾﺗﺎل‬ 2) Mobile Devices. 3) Personal Computers (Microcomputers). ( ) 4) Midrange Servers (Minicomputers). ‫ﺳﯾرﻓر ﯾﺷﺗﻐل ﻋﻠﯾﮫ ﺷرﻛﮫ ﻣﺗوﺻﻠﺔ ﺑﯾﮫ‬ 5) Mainframe Computers (High-end Servers). ‫ﯾﺷﺗﻐل ﻓﻲ ﻣﺳﺗﺷﻔﻲ او ﺟﺎﻣﻌﮫ‬ ‫ﻣﯾﻧﻔﻌش ﺗﺷﺗﻐل ع ﺳﯾرﻓر‬ 6) Supercomputers (Supercomputing Cluster). ‫ﻋﻠﻲ ﻣﺳﺗوي اﻟدول‬ 11 Types of Software.. Classification of Computer Systems.. 1) Embedded Computers; Often embedded into household appliances (washing machines, stove, ), Cars,.. etc. Designed to perform specific tasks or functions for that product. 2) Mobile Devices; Very small device with some type of built-in computing or Internet capability. E.g., Smart phones, Smart watches, Portable digital media players,.. etc. 3) Personal Computers; Computer systems designed to be used by one person at a time, also called a microcomputer. E.g., Desktop PCs, Portable PCs (notebook/laptop, or Tablets). 4) Midrange Servers; A medium-sized computer used to host programs and data for a small network, also called a minicomputer. Users connect via a network with a Desktop PC, Portable PC, or a Dumb Terminal consisting of just a monitor and keyboard. 12 Types of Software.. Classification of Computer Systems.. 5) Mainframe Computers; Larger, more expensive, and more powerful than midrange servers. Used by several large organizations (e.g., hospitals, universities, large businesses, banks, government offices) to manage large amounts of centralized data. Located in climate- controlled data centers & connected to the rest of the company computers via a network, & usually operate 24 hours a day. 6) Super Computers; Fastest, most expensive, most powerful type of computers. Commonly built by connecting hundreds of smaller computers (a supercomputing cluster). Used for space exploration, satellites, weather forecast, oil exploration, scientific 13 research, etc. Your First C Program.. Keywords, Functions,.. &.. Syntax Rules 14 The MAIN Function o main is the function name. o int: means that the main function returns an integer value. #include int main(void) // Program execution begins here { printf( “Hello, World!\n” ); return 0; // program ended successfully } o (void): means that the main function doesn’t receive any information. o The "Function Body" is written between the left brace { and the right brace }. 15 The MAIN Function #include int main(void) // Program execution begins here { printf( “Hello, World!\n” ); return 0; // program ended successfully } o Any C program should contain at least the MAIN function. o Any C program begins executing at the MAIN function. 16 A Statement o An instruction = A statement. #include int main(void) // Program execution begins here { printf( “Hello, World!\n” ); return 0; // program ended successfully } o It instructs the computer to perform an action. o Every statement must end in a semi-colon ";". 17 The PRINTF Function #include int main(void) // Program execution begins here { printf( “Hello, World!\n” ); return 0; // program ended successfully } o The PRINTF function prints on the screen the string of characters between the double quotations (“ ”). o The f in PRINTF stands for “formatted”. o The message is displayed as formatted between the “ ”, 18 except for the \n which is an escape sequence. A String #include int main(void) // Program execution begins here { printf( “Hello, World!\n” ); return 0; // program ended successfully } o A string in C (also known as C string) is an array of characters, followed by a NULL character. To represent a string, a set of characters are enclosed within double quotes (“ “). 19 Escape Sequences o An escape sequence is a sequence of characters that does not represent itself when used inside a character or string literal, but is translated into another character or a sequence of characters. #include int main(void) // Program execution begins here { printf( “Hello, World!\n” ); return 0; // program ended successfully } o In C, all escape sequences consist of two or more characters, the first of which is the backslash, \ (called the "Escape character"); the remaining characters determine the interpretation of the escape sequence. For example, \n is an escape sequence that denotes a newline character. 20 Escape Sequences Escape Sequence Description \n New Line Example: printf ( "Welcome\n to\n C!\n"); Output: Welcome to C! \t Tab Example: printf ( "Welcome\t to C!\n" ); Output: Welcome to C! \a Alert Sound \\ Backslash \” Double Quotation Example: printf( "My name is \"Ahmed \" / Mohamed \\" ); Output: My name is "Ahmed" / Mohamed \ 21 21 Preprocessor Directives Lines starting with a # are: o Directives to the C preprocessor. #include int main(void) // Program execution begins here { printf( “Hello, World!\n” ); return 0; // program ended successfully } o They are processed before the program is compiled. o They are NOT instructions. o #include tells the preprocessor to include the contents of the into the program. 22 Header File #include int main(void) // Program execution begins here { printf( “Hello, World!\n” ); return 0; // program ended successfully } o is a header file that contains information used by the compiler when compiling calls to library functions (builtin functions) such as printf. o stands for STandarD Input/Output.Header 23 The RETURN Statement #include int main(void) // Program execution begins here { printf( “Hello, World!\n” ); return 0; // program ended successfully } o At the end of every MAIN function. o The keyword return is used to exit a function. 24 Why does the MAIN function return a 0? #include int main(void) // Program execution begins here { printf( “Hello, World!\n” ); return 0; // program ended successfully } o The value 0 (which in an integer) indicates that the program has terminated successfully. 25 Comments o Do not cause the computer to perform any action when the program is running. Therefore, comments do nothing, they are NOT instructions. #include int main(void) // Program execution begins here { printf( “Hello, World!\n” ); return 0; // program ended successfully } o Comments are used to improve the program’s readability, and to help others read and understand your program. There are two forms: a) for multiple-lined comments. b) //.... for single-lined comments. 26 Blank-lines, Spaces, Tabs,.. etc. #include  int main(void) // Program execution begins here  { printf( “Hello, World!\n” ); return 0; // program ended successfully } o N.B. Blank-lines, Spaces, Tabs are also ignored by the compiler. o Only use them to improve a program’s readability. o We can write more than an instruction in the same line, but doing that will affect the readability. 27 This program is written in C, which is a High-Level Language.. #include int main(void) // Program execution begins here { printf( “Hello, World!\n” ); return 0; // program ended successfully } How is it translated into Machine Code? 28 Thanks!.. Questions? 29

Use Quizgecko on...
Browser
Browser