Introduction to Programming Concepts

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Listen to an AI-generated conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

Which of the following best describes the role of a programming language?

  • To translate binary data into human-readable text.
  • To execute actions without human intervention.
  • To provide a medium for humans to communicate instructions to a computer. (correct)
  • To serve as a direct interface between hardware components.

What is the primary reason machine code is difficult for humans to understand?

  • It uses complex mathematical equations.
  • It is written in a language specific to each operating system.
  • It requires a deep understanding of hardware architecture.
  • It consists of a series of 0s and 1s. (correct)

Why are intermediary languages necessary in the context of computer programming?

  • To create self-executing programs.
  • To provide a human-understandable way to write code that can be translated into machine code. (correct)
  • To directly interact with the computer processor.
  • To bypass the need for machine code.

What is the function of compilers and interpreters in the programming process?

<p>They allow the computer to process high-level language code by translating it into machine code. (A)</p>
Signup and view all the answers

Which classification of programming languages is characterized by a high level of abstraction and easier human understanding?

<p>High Level Languages (D)</p>
Signup and view all the answers

What characteristic distinguishes low-level languages from high-level languages?

<p>Closeness to machine understanding (D)</p>
Signup and view all the answers

Which of the following programming languages requires a compiler or interpreter for translation?

<p>C#. (D)</p>
Signup and view all the answers

Based on translation method, how is Java categorized?

<p>Intermediary language (A)</p>
Signup and view all the answers

Which programming paradigm focuses on structuring code into reusable components, emphasizing data and methods?

<p>Object-oriented programming (A)</p>
Signup and view all the answers

Which of the following is a characteristic of C#?

<p>Type safe. (C)</p>
Signup and view all the answers

Which element is essential for a basic C# program?

<p>A Main method. (B)</p>
Signup and view all the answers

In C#, what is the significance of a semicolon (;)?

<p>It terminates every expression and statement. (D)</p>
Signup and view all the answers

How does C# treat uppercase and lowercase letters in code?

<p>It is case sensitive. (C)</p>
Signup and view all the answers

What is the primary function of data types in C#?

<p>To specify the type of information a variable can store. (C)</p>
Signup and view all the answers

Why is C# characterized as a strongly typed language?

<p>Because variable data types must be specified, and the compiler is aware of the expected data type. (D)</p>
Signup and view all the answers

In C#, which category do string and object data types belong to?

<p>Reference types (A)</p>
Signup and view all the answers

What is a key property of 'data variables' in programming?

<p>They are memory locations that can hold data that changes during project execution. (C)</p>
Signup and view all the answers

In C#, how would you declare a constant variable?

<p>using the keyword <code>CONST</code>. (D)</p>
Signup and view all the answers

What happens when a variable is declared within a program?

<p>The compiler reserves an area of memory and assigns it a name (identifier). (C)</p>
Signup and view all the answers

Which of the following is a guideline for creating a valid identifier in C#?

<p>Must not be a keyword. (D)</p>
Signup and view all the answers

In the context of programming, what is 'assignment'?

<p>Changing the value of the variable. (B)</p>
Signup and view all the answers

What does an operator do in C#?

<p>It tells the compiler to perform specific mathematical or logical manipulations. (C)</p>
Signup and view all the answers

What is the purpose of 'arithmetic operators' in programming?

<p>To perform mathematical calculations. (B)</p>
Signup and view all the answers

If variable A holds 10, what would be the outcome of the operation A++?

<p>11 (B)</p>
Signup and view all the answers

Which C# function is used to compute the square root of a number?

<p>sqrt() (C)</p>
Signup and view all the answers

What is the purpose of relational operators in C#?

<p>To compare two operands. (B)</p>
Signup and view all the answers

Given A = 10 and B = 20, which expression would evaluate to true?

<p>A &lt; B (B)</p>
Signup and view all the answers

What do logical operators primarily evaluate?

<p>Boolean values (D)</p>
Signup and view all the answers

What does the && operator signify in the context of logical operations?

<p>Logical AND (A)</p>
Signup and view all the answers

What is the main function of assignment operators in C#?

<p>To assign values to variables. (C)</p>
Signup and view all the answers

What operation does the += assignment operator perform?

<p>Addition (C)</p>
Signup and view all the answers

In the expression C %= A, what operation is performed?

<p>C is assigned the modulus of C divided by A. (B)</p>
Signup and view all the answers

Which type of programming language is designed to program the computer at a very low level of abstraction?

<p>Low Level Languages (D)</p>
Signup and view all the answers

Which language is tailored for real-time applications and directly interacts with hardware?

<p>ADA (C)</p>
Signup and view all the answers

What is the role of variables in programming?

<p>To store, calculate and for reusability. (D)</p>
Signup and view all the answers

Which function breaks a value into fractional and integer parts?

<p>modf() (C)</p>
Signup and view all the answers

Which of the following programming paradigms allows the programming of the computer using a sequence of commands?

<p>Imperative programming (A)</p>
Signup and view all the answers

How can the value inside a variable be changed?

<p>Assignment (B)</p>
Signup and view all the answers

Which language is suited for system object programming?

<p>C++ (C)</p>
Signup and view all the answers

Flashcards

Programming Language

A medium designed to allow humans to give instructions or describe consecutive actions to be executed by a computer.

Machine code

The language used directly by the processor.

Binary data

Consists of a series of 0s and 1s.

High level language

Programming languages with a high level of abstraction i.e. Closer to human understanding.

Signup and view all the flashcards

Low level language

Programming languages is designed to program the computer at very low-level of abstraction; i.e. Machine Level.

Signup and view all the flashcards

Compiler

Translates source code into machine code all at once.

Signup and view all the flashcards

Interpreter

Translates source code one line at a time during execution.

Signup and view all the flashcards

Java

Programming language where Internet is the main application area.

Signup and view all the flashcards

Object-oriented Programming

Programming language based on a programming paradigm that focuses on using objects.

Signup and view all the flashcards

Simple

A feature of C# that is simple.

Signup and view all the flashcards

Modern

A feature of C# that is modern programming language.

Signup and view all the flashcards

Object oriented

Feature of C# that is object oriented.

Signup and view all the flashcards

Namespace Declaration

Basic elements of C# programs that is a container for classes.

Signup and view all the flashcards

Class

Basic elements of C# programs that encapsulate data and methods.

Signup and view all the flashcards

Main Method

Basic elements of C# programs. The entry point of execution.

Signup and view all the flashcards

Statements and Expressions

Basic elements of C# programs. Instructions executed by the computer.

Signup and view all the flashcards

Comment

Basic elements of C# programs. Explanations or notes in the code.

Signup and view all the flashcards

Case sensitivity

C# is case sensitive.

Signup and view all the flashcards

Main method

C# program execution starts at the Main method.

Signup and view all the flashcards

Data Type

The type of data that a variable declaration specifies and defines what type of information will be stored in the allocated memory space.

Signup and view all the flashcards

C# Type System

A strongly typed language.

Signup and view all the flashcards

Value Types

Categories of data types in C#.

Signup and view all the flashcards

Reference Types

Categories of data types in C#.

Signup and view all the flashcards

Data Variables

Memory or storage locations that hold data that can be changed during project execution.

Signup and view all the flashcards

Constants

Memory locations that hold data that cannot be changed during project execution.

Signup and view all the flashcards

Const

Keyword used to declare a constant.

Signup and view all the flashcards

Declaring a Variable

Reserves an area of memory and assigns it a name.

Signup and view all the flashcards

Assignment Operator

Used to change the value of a variable.

Signup and view all the flashcards

Operator

The use of a symbol that tells the compiler to perform specific mathematical or logical manipulations.

Signup and view all the flashcards

Arithmetic Operators

Operators that perform mathematical calculations.

Signup and view all the flashcards

sqrt()

Returns the square root

Signup and view all the flashcards

pow()

Raises one value to a power.

Signup and view all the flashcards

Relational Operators

Operators that compare values.

Signup and view all the flashcards

Operator

Returns true if one operand is greater than the other.

Signup and view all the flashcards

< Operator

Returns true if one operand is lesser than the other.

Signup and view all the flashcards

Logical Operators

Operators that perform logical operations.

Signup and view all the flashcards

&& Operator

Checks if two conditions are both true.

Signup and view all the flashcards

|| Operator

Checks if at least one condition is true.

Signup and view all the flashcards

= Operator

Assigns a value to variable.

Signup and view all the flashcards

+= Operator

Combines addition and an assignment.

Signup and view all the flashcards

Study Notes

Course Design

  • Course code is GL/MN-351
  • Course credits are (2,1,2)
  • The course prerequisite is Computer Programming
  • A reference is "C# Programming From Problem Analysis to Program Design, 5th Edition or 3rd Edition" by Barbara Doyle, published by Cengage in 2016 (1088 pp) or 2010 (832pp)

Course Outline

  • Elements of programming
  • Data description statements
  • Control structures
  • Data types
  • Data-processing statements
  • Input and output (I/O) statements
  • Procedure for writing algorithms
  • Building applications
  • Steps in developing applications
  • Decisions
  • Conditions and loops
  • Arithmetic operators
  • Programming applications in Engineering

Evaluation Methods

  • Assignments
  • Labs
  • Quizzes
  • Final Exam

Introduction to Programming

  • A programming language enables humans to provide instructions describing actions for a computer
  • The processor uses machine code
  • Binary data, consisting of 0s and 1s, reaches the processor
  • Machine code is generally difficult for humans to understand
  • There is a need for intermediary languages that humans can understand
  • Compilers and interpreters translate code into machine code for the computer to process
  • Programming languages can be classified based on levels of abstraction, how codes are translated to machine code, and programming paradigm

Levels of Abstraction

  • Low-level languages have very low abstraction, closer to machine level.
  • High-level languages have a high level of abstraction, closer to human understanding.
  • Low-level languages are difficult for humans and machine dependent and include machine and assembly language
  • High-level languages require translation by a compiler or interpreter and Machine Independent languages, like C++, VB and C#

Code Translation

  • Languages can be classified as Compiled, Interpreted, or Intermediary
  • ADA is a compiled language for real-time applications
  • BASIC is an interpreted language for educational purposes
  • C is a compiled language for system programming
  • C++ is a compiled language for system object programming
  • Cobol is a compiled language for management
  • Fortran is a compiled language for calculation
  • Java is an intermediary language for internet-oriented programming
  • MATLAB is an interpreted language for mathematical calculations

Programming Paradigm

  • Languages can be classified as Object-oriented, Imperative or procedural, Concurrent, Functional, or Scripting

C#

  • This course will focus on computer programming using C#
  • C# is simple, modern, and object-oriented
  • C# is type-safe, interoperable, scalable, updateable and component-oriented
  • Basic C# programs consist of a namespace declaration, a class, the Main method, statements and expressions, and comments

C# program structure

  • using System;
  • namespace HelloWorldApplication
  • Inside the namespace is the class, class HelloWorld
  • Inside the class is the main method, static void Main(string[] args)
  • Inside the main method is where you make comments /* my first program in C# */
  • And statements, Console.Writeline("Hello World");
  • C# is case sensitive
  • C# program execution starts at the Main method
  • All C# expressions and statements must end with a semicolon (;)
  • File names can be different from the class name

Data Types

  • Data types specify the type of information stored in a variable's allocated memory space
  • C# requires specifying the data type of a variable during declaration so that it is strongly typed, and the compiler is aware of what type of data is expected
  • Grade point average is often a double
  • Age is often an int
  • Full name is often a string
  • Final grade is often a char
  • Data types are divided into value types, reference types, and pointer types

Data Variables

  • Data variables are memory locations that hold data that can be changed during project execution
  • Every variable has a type that determines what values can be stored
  • They are used for storing values, calculating, and reusability

Constants

  • Constants are memory locations that hold data that cannot be changed during project execution
  • Use the keyword CONST, and are given a name, a data type, and a value
  • const type identifier = expression;

Declaring Variables

  • Declaring a variable or named constant reserves a memory area and assigns it an identifier name
  • Identifier names are specified according to recommended naming conventions
  • The syntax for declaring a variable is DataType VariableName;
  • Rules for creating an identifier include that they use a combination of alphabetic characters (a-z and A-Z), numeric digits (0-9), and the underscore, and that the first character be alphabetic
  • There should be no embedded spaces and identifiers must not use keywords
  • Use the case of the character to your advantage, be descriptive with meaningful names, and follow naming conventions or general naming conventions
  • int studentCount; // number of students in the class

Assignment

  • Assignment is used to change the value of a variable
  • The assignment operator is (=)
  • The syntax is variable = expression;
  • Expressions can be another variable, a compatible literal value, a mathematical equation, a call to a method that returns a compatible value, or A combination of one or more items in this list
  • To store a value in a variable you must use an =. Here is an example of how to store the value 5 inside an integer variable. MyInt = 5;
  • You can store a value inside a variable when you declare it. This is called initializing the variable. int MyInt = 5;

Operators

  • An operator is a symbol that instructs the compiler to perform specific mathematical or logical manipulations
  • C# has a rich set of built-in operators
  • C# uses arithmetic, relational, logical, and assignment operators

Arithmetic Operations

  • The simplest form of an assignment statement is resultVariable = operand1 operator operand2;
  • Readability is improved by using a space before and after every operator
  • Supported arithmetic operators:
    • + Adds two operands: A + B = 30
    • - Subtracts the second operand from the first: A - B = -10
    • * Multiplies both operands: A * B = 200
    • / Divides numerator by de-numerator: B / A = 2
    • % Modulus Operator and remainder after integer division: B % A = 0
    • ++ Increment operator increases integer value by one: A++ = 11
    • -- Decrement operator decreases integer value by one: A-- = 9

Mathematical Functions

  • Common C# math functions include:
    • sqrt() Computes square root, e.g., sqrt(16)=4
    • pow() Raise one value to a power, e.g., pow(2,3)=8
    • log() Compute natural logarithm, e.g., log(5.5)=1.704748
    • log10() Compute common logarithm, e.g., log10(1000)=3
    • modf() Break into fractional and integral parts, e.g., modf(3.14)=3.00+0.14
    • cos() Computes cosine of an angle of x radians, e.g., cos(60*PI/180)=0.5 (i.e., the cos of 60 degrees is 0.5)

Increment and Decrement Operations

  • Increment/Decrement operations:
    • num++; increment // num = num + 1;
    • --valuel; decrement // value = value – 1;
  • There is preincrement/predecrement versus post
    • int num = 100;
    • messagebox.show (num++); // Displays 100
    • messagebox.show(num); // Display 101
    • messagebox.show(++num); // Displays 102

Relational Operators

  • Relational operators compare two values.
  • The relational operators supported by C# include:
    • == Checks if the values of two operands are equal or not; if yes, then the condition becomes true. (A == B) is not true.
    • != Checks if the values of two operands are equal or not; if values are not equal, then the condition becomes true. (A != B) is true.
    • > Checks if the value of the left operand is greater than the value of the right operand; if yes, then the condition becomes true. (A > B) is not true.
    • < Check if the value of the left operand is less than the value of the right operand; if yes, then the condition becomes true. (A < B) is true.
    • >= Checks if the value of left operand is greater than or equal to the value of the right operand; if yes, then the condition becomes true. (A >= B) is not true.
    • <= Checks if the value of the left operand is less than or equal to the value of the right operand; if yes, then condition becomes true. (A <= B) is true.

Logical Operators

  • Logical operators take Boolean values as operands and returns a Boolean value.
  • The logical operators supported by C#:
    • && Called Logical AND operator. If both the operands are non-zero, then the condition becomes true. (A && B) is false.
    • || Called Logical OR Operator. If any of the two operands is non-zero, then the condition becomes true. (A || B) is true.
    • ! Called Logical NOT Operator. Use to reverse the logical state of its operand. If the condition is true, then the Logical NOT operator will make it false. !(A && B) is true.

Assignment Operators

  • Assignment operators are used to assign values to variables.
  • The assignment operators supported by C# :
    • = Simple assignment operator. Assigns values from the right-side operands to the left-side operand. C = A + B assigns value of A + B into C
    • += Add AND assignment operator. It adds the right operand to the left operand and assigns the result to left operand. C += A is equivalent to C = C + A
    • -= Subtract AND assignment operator. It subtracts right operand from the left operand and assigns the result to left operand. C -= A is equivalent to C = C - A
    • *= Multiply AND assignment operator. It multiplies the right operand with the left operand and assigns the result to left operand. C *= A is equivalent to C = C * A
    • /= Divide AND assignment operator. It divides the left operand with the right operand and assigns the result to left operand. C /= A is equivalent to C = C / A
    • %= Modulus AND assignment operator. It takes modulus using two operands and assigns the result to left operand. C %= A is equivalent to C = C % A

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

More Like This

Computer Science Concepts Quiz
9 questions
Introduction to Computer Programming
10 questions
History of Programming Languages
24 questions
Use Quizgecko on...
Browser
Browser