Share
C Programming

Course Outline

Week 1

COMPUTER SCIENCE AS A CAREER

  • Why Computer Science May be the right field for you
  • Computer Disciplines
  • Career Opportunities

OVERVIEW OF COMPUTERS AND PROGRAMS

  • Computer Hardware
  • Computer Software
  • The Software Development Method
  • Professional Ethics for Computer Programmers
Week 2
Week 3
Week 4
Week 5

SponsoredAdvertise

Why Computer Science May be the right field for you


Almost everything we do is influenced by computing.

Previous generations are not as comfortable with technology and try to solve problems without always thinking of technology first. Many people in the workforce resist the changes that technology requires. They often turn to the youngest employees to take over technology issues and to make choices that will have important consequences.

This difference among generations creates a great environment for bright and dedicated students to choose to major in computer science or a related field.

The computer industry is one of the fastest growing segments of our economy and promises to continue to see growth well into the future. In order to be competitive, businesses must continue to hire well-trained professionals not only to produce high quality products for the present, but also to plan creative scientific and engineering advances for the future.


Traits of a Computer Scientist

You must love the challenge of solving problems. Computer science is more about finding solutions to problems than it is about using the current computer hardware or programming language. Solving problems requires being creative and “thinking outside the box.” You must be willing to try things that are different from the “accepted” solution.

You like to build things that are useful to people and that will have a positive impact on their lives.


Computer Disciplines


A career involving computing requires the individual to focus his or her efforts while obtaining a college degree.


Career Opportunities


Software engineers, Computer Systems analysts, Mathematicians, Computer Programmers, Web Designers and Developers.


Computer Hardware


Despite significant variations in cost, size, and capabilities, modern computers

resemble one another in many basic ways. Essentially, most consist of the following

components:

  • Main memory

  • Secondary memory, which includes storage devices such as hard disks, CDs,DVDs, and flash drives

  • Central processing unit

  • Input devices, such as keyboards, mouses, touch pads, scanners, joysticks

  • Output devices, such as monitors, printers, and speakers

Figure: Component of a computer


Anatomy of Memory 

Imagine the memory of a computer as an ordered sequence of storage locations called memory cells.

To store and access information, the computer must have some way of identifying the individual memory cells. Therefore, each memory cell has a unique address that indicates its relative position in memory. 

Most computers, however, have millions of individual memory cells, each with its own address.

The data stored in a memory cell are called the contents of the cell. Every memory cell always has some contents, although we may have no idea what they are.


Computer Software

Lists of instructions.


Operating System


The collection of computer programs that control the interaction of the user and the computer hardware is called the operating system (OS) . The operating system of a computer is often compared to the conductor of an orchestra, for it is the software that is responsible for directing all computer operations and managing all computer resources.


Responsibilities Of Operating System


  1. Communicating with the computer user: receiving commands and carrying them out or rejecting them with an error message.
  2. Managing allocation of memory, of processor time, and of other resources for various tasks.
  3. Collecting input from the keyboard, mouse, and other input devices, and providing this data to the currently running program.
  4. Conveying program output to the screen, printer, or other output device.
  5. Accessing data from secondary storage.
  6. Writing data to secondary storage.


In addition to these responsibilities, the operating system of a computer with multiple users must verify each individual’s right to use the computer and must ensure that each user can access only data for which he or she has proper authorization.


Application Software


Application programs are developed to assist a computer user in accomplishing specific tasks. For example, a word-processing application such as Microsoft Word  or OpenOffice.org Writer helps to create a document, a spreadsheet application such as Microsoft Office Excel helps to automate tedious numerical calculations and to generate charts that depict data, and a database management application such as Microsoft Office Access or dBASE assists in data storage and quick keyword-based access to large collections of records.


Computer Languages


Developing new software requires writing lists of instructions for a computer to

execute. However, software developers rarely write in the language directly understood by a computer, since this machine language is a collection of binary numbers.

Another drawback of machine language is that it is not standardized: There is a different machine language for every type of CPU. This same drawback also applies to the somewhat more readable assembly language , a language in which computer operations are represented by mnemonic codes rather than binary numbers and variables can be given names rather than binary memory addresses.


Figure: A Machine Language Program Fragment and Its Assembly Language Equivalent


To write programs that are independent of the CPU on which they will be executed, software designers use high-level languages that combine algebraic expressions and symbols taken from English. For example, the machine/assembly language program fragment shown in the figure above would be a single statement in a high-level language:

a = a + b;

This statement means “add the values of variables a and b , and store the result in variable a (replacing a ’s previous value).”

Before a high-level language program can be executed, it must first be translated into the target computer’s machine language. The program that does this translation is called a compiler.

The input to the compiler is a source file containing the text of a high-level language program.

The software developer creates this file by using a word processor or editor. The format of the source file is text, which means that it is a collection of character codes. For example, you might type a program into a file called myprog.c. The compiler will scan this source file, checking the program to see if it follows the high-level language’s syntax (grammar) rules. If the program is syntactically correct, the compiler saves in an object file the machine language instructions that carry out the program’s purpose. For program myprog.c , the object file created might be named myprog.obj . Notice that this file’s format is binary. This means that you should not send it to a printer, display it on your monitor, or try to work with it in a word processor because it will appear to be meaningless garbage to a word processor, printer, or monitor. If the source program contains syntax errors, the compiler lists these errors but does not create an object file. The developer must return to the word processor, correct the errors, and recompile the program.

Although an object file contains machine instructions, not all of the instructions are complete. High-level languages provide the software developer with many named chunks of code for operations that the developer will likely need. Almost all high-level language programs use at least one of these chunks of code called functions that reside in other object files available to the system. The linker program combines these prefabricated functions with the object file, creating a complete.

Machine language program that is ready to run. For your sample program, the linker might name the executable file it creates myprog.exe .


Figure: Entering, Translating, and Running a High-Level Language Program


As long as myprog.exe is just stored on your disk, it does nothing. To run it,  the loader must copy all its instructions into memory and direct the CPU to begin execution with the first instruction. As the program executes, it takes input data from one or more sources and sends results to output and/or secondary storage devices.

Most high-level language compilers are sold as part of an integrated development environment (IDE) , a package that combines a simple word processor with a compiler, linker, and loader. 

Such environments give the developer menus from which to select the next step, and if the developer tries a step that is out of sequence, the environment simply fills in the missing steps automatically.

The user of an integrated development environment should be aware that the environment may not automatically save to disk the source, object, and executable files. Rather, it may simply leave these versions of the program in memory. Such an approach saves the expenditure of time and disk space needed to make copies and keeps the code readily available in memory for application of the next step in the translation/execution process. However, the developer can risk losing the only copy of the source file in the event of a power outage or serious program error. 

To prevent such a loss when using an IDE, be sure to explicitly save the source file to disk after every modification before attempting to run the program.

We will be using Code Block as our Integrated Development Environment

Please download code block if you don't have it yet. You can download code block via this url: Download code block

Remember to choose the The codeblocks-20.03mingw-setup.exe file which includes additionally the GCC/G++/GFortran compiler and GDB debugger from MinGW-W64 project


Executing a Program


To execute a machine language program, the CPU must examine each program instruction in memory and send out the command signals required to carry out the instruction. Although the instructions normally are executed in sequence, as we will discuss later, it is possible to have the CPU skip over some instructions or execute some instructions more than once.

During execution, data can be entered into memory and manipulated in some specified way. Special program instructions are used for entering or scanning a program’s data (called input data ) into memory. After the input data have been processed, instructions for displaying or printing values in memory can be executed to display the program results. The lines displayed by a program are called the program output .


Integrated Development Environment (IDE) 


Software package combining a word processor, compiler, linker, loader, and tools for finding errors.


Input Data 


The data values that are scanned by a program.


Program Output 


The lines displayed by a program

Figure: Flow of information during a water bill program execution.


PRACTICALS


  • Installation of Code Block

  • Creating your first c program


INSTALLATION OF CODE BLOCK


If you haven't installed the code block yet, please do so. Visit the site to download the software and install. The link to the site is already stated above. Please follow the link and install the code block software.


CREATING YOUR FIRST C PROGRAM


Start the CodeBlock


Figure: CodeBlock


To create a project, click on File -> New -> Project


 Figure: New Project creation


Select the project type. 


We will be developing console applications in this course. So select the Console Application option.


 Figure: Console Application


Click Next and select C



Fill the Project Title, browse to where to save your project 


 Figure: Project Creation Form 

 

 Figure: Project Name Details


Click on next


 Figure: Compiler Selection Form


Click on Finish


 Figure: C Program Project


Click on Source to view the source files /Codes


Double click on the main source file



Run the application by clicking on

SponsoredAdvertise

Kuulchat Premium