Podcast
Questions and Answers
Which of the following best describes the role of a programming language?
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?
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?
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?
What is the function of compilers and interpreters in the programming process?
Which classification of programming languages is characterized by a high level of abstraction and easier human understanding?
Which classification of programming languages is characterized by a high level of abstraction and easier human understanding?
What characteristic distinguishes low-level languages from high-level languages?
What characteristic distinguishes low-level languages from high-level languages?
Which of the following programming languages requires a compiler or interpreter for translation?
Which of the following programming languages requires a compiler or interpreter for translation?
Based on translation method, how is Java categorized?
Based on translation method, how is Java categorized?
Which programming paradigm focuses on structuring code into reusable components, emphasizing data and methods?
Which programming paradigm focuses on structuring code into reusable components, emphasizing data and methods?
Which of the following is a characteristic of C#?
Which of the following is a characteristic of C#?
Which element is essential for a basic C# program?
Which element is essential for a basic C# program?
In C#, what is the significance of a semicolon (;)?
In C#, what is the significance of a semicolon (;)?
How does C# treat uppercase and lowercase letters in code?
How does C# treat uppercase and lowercase letters in code?
What is the primary function of data types in C#?
What is the primary function of data types in C#?
Why is C# characterized as a strongly typed language?
Why is C# characterized as a strongly typed language?
In C#, which category do string
and object
data types belong to?
In C#, which category do string
and object
data types belong to?
What is a key property of 'data variables' in programming?
What is a key property of 'data variables' in programming?
In C#, how would you declare a constant variable?
In C#, how would you declare a constant variable?
What happens when a variable is declared within a program?
What happens when a variable is declared within a program?
Which of the following is a guideline for creating a valid identifier in C#?
Which of the following is a guideline for creating a valid identifier in C#?
In the context of programming, what is 'assignment'?
In the context of programming, what is 'assignment'?
What does an operator do in C#?
What does an operator do in C#?
What is the purpose of 'arithmetic operators' in programming?
What is the purpose of 'arithmetic operators' in programming?
If variable A holds 10, what would be the outcome of the operation A++
?
If variable A holds 10, what would be the outcome of the operation A++
?
Which C# function is used to compute the square root of a number?
Which C# function is used to compute the square root of a number?
What is the purpose of relational operators in C#?
What is the purpose of relational operators in C#?
Given A = 10 and B = 20, which expression would evaluate to true?
Given A = 10 and B = 20, which expression would evaluate to true?
What do logical operators primarily evaluate?
What do logical operators primarily evaluate?
What does the &&
operator signify in the context of logical operations?
What does the &&
operator signify in the context of logical operations?
What is the main function of assignment operators in C#?
What is the main function of assignment operators in C#?
What operation does the +=
assignment operator perform?
What operation does the +=
assignment operator perform?
In the expression C %= A
, what operation is performed?
In the expression C %= A
, what operation is performed?
Which type of programming language is designed to program the computer at a very low level of abstraction?
Which type of programming language is designed to program the computer at a very low level of abstraction?
Which language is tailored for real-time applications and directly interacts with hardware?
Which language is tailored for real-time applications and directly interacts with hardware?
What is the role of variables in programming?
What is the role of variables in programming?
Which function breaks a value into fractional and integer parts?
Which function breaks a value into fractional and integer parts?
Which of the following programming paradigms allows the programming of the computer using a sequence of commands?
Which of the following programming paradigms allows the programming of the computer using a sequence of commands?
How can the value inside a variable be changed?
How can the value inside a variable be changed?
Which language is suited for system object programming?
Which language is suited for system object programming?
Flashcards
Programming Language
Programming Language
A medium designed to allow humans to give instructions or describe consecutive actions to be executed by a computer.
Machine code
Machine code
The language used directly by the processor.
Binary data
Binary data
Consists of a series of 0s and 1s.
High level language
High level language
Signup and view all the flashcards
Low level language
Low level language
Signup and view all the flashcards
Compiler
Compiler
Signup and view all the flashcards
Interpreter
Interpreter
Signup and view all the flashcards
Java
Java
Signup and view all the flashcards
Object-oriented Programming
Object-oriented Programming
Signup and view all the flashcards
Simple
Simple
Signup and view all the flashcards
Modern
Modern
Signup and view all the flashcards
Object oriented
Object oriented
Signup and view all the flashcards
Namespace Declaration
Namespace Declaration
Signup and view all the flashcards
Class
Class
Signup and view all the flashcards
Main Method
Main Method
Signup and view all the flashcards
Statements and Expressions
Statements and Expressions
Signup and view all the flashcards
Comment
Comment
Signup and view all the flashcards
Case sensitivity
Case sensitivity
Signup and view all the flashcards
Main method
Main method
Signup and view all the flashcards
Data Type
Data Type
Signup and view all the flashcards
C# Type System
C# Type System
Signup and view all the flashcards
Value Types
Value Types
Signup and view all the flashcards
Reference Types
Reference Types
Signup and view all the flashcards
Data Variables
Data Variables
Signup and view all the flashcards
Constants
Constants
Signup and view all the flashcards
Const
Const
Signup and view all the flashcards
Declaring a Variable
Declaring a Variable
Signup and view all the flashcards
Assignment Operator
Assignment Operator
Signup and view all the flashcards
Operator
Operator
Signup and view all the flashcards
Arithmetic Operators
Arithmetic Operators
Signup and view all the flashcards
sqrt()
sqrt()
Signup and view all the flashcards
pow()
pow()
Signup and view all the flashcards
Relational Operators
Relational Operators
Signup and view all the flashcards
Operator
Operator
Signup and view all the flashcards
< Operator
< Operator
Signup and view all the flashcards
Logical Operators
Logical Operators
Signup and view all the flashcards
&& Operator
&& Operator
Signup and view all the flashcards
|| Operator
|| Operator
Signup and view all the flashcards
= Operator
= Operator
Signup and view all the flashcards
+= Operator
+= Operator
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.