Posts

Showing posts from January, 2024
Image
ICT/2022/139 R.S.R. Ranathunga   Tutorial 04 & 05(Pseudocode) 1. Generate students repot as shown below.  Index Number Name Mathematics Physics Chemistry Total Average Grade   In this task list, for each student you must input marks of three subjects. Students’ grade is determined according to following criteria:  • Average >= 90%: Grade A  • Average >= 80%: Grade B  • Average >= 70%: Grade C  • Average >= 60%: Grade D  • Average >= 40%: Grade E   • Average < 40%: Grade F  1) What output do you need to generate? Display a student report -Index number, Name, Mathematics  subject marks as M, Physics subject marks as P, Chemistry subject marks as C , Total, Average, Grade  2) What input do you have/ need? Index number, Name, Mathematics subject marks as M, Physics subject marks as P, Chemistry subject marks as C  3) What form will it be in? Index number as String, Name as Text, Mathematics subj...
Image
ICT/2022/139 R.S.R. Ranathunga   Tutorial 03 1) Swap two values stored in two different variables.  1. What output do you need to generate? Display A and B swapped value  2. What input do you have/ need? Input Number 1 as A Input number 2 as B  3. What form will it be in? Integer value of Number 1 Integer value of Number 2  4. Will the program have a list of tasks that needs to be done repeatedly (LOOP)? No  5. What are the other major tasks of the program?  Input A  Input B Declare “C” as Integer  Assign A to C  Assign B to A  Assign C to B  Display A, B 2) Check whether an entered number is negative, positive.  1. What output do you need to generate? Display message status of an entered number  2. What input do you have/ need? A number as x  3. What form will it be in? Numerical value  4. Will the program have a list of tasks that needs to be done repeatedly (LOOP)? No  5. What are the other major tas...
ICT/2022/139 R.S.R. Ranathunga Tutorial 02  1) Swap two values stored in two different variables.  1. What output do you need to generate? Display A and B swapped value  2. What input do you have/ need? Input Number 1 as A Input number 2 as B  3. What form will it be in? Integer value of Number 1 Integer value of Number 2  4. Will the program have a list of tasks that needs to be done repeatedly (LOOP)? No  5. What are the other major tasks of the program?  Input A  Input B Declare “C” as Integer  Assign A to C  Assign B to A  Assign C to B  Display A, B 2  2) Check whether an entered number is negative, positive.  1. What output do you need to generate? Display message status of an entered number  2. What input do you have/ need? A number as x  3. What form will it be in? Numerical value  4. Will the program have a list of tasks that needs to be done repeatedly (LOOP)? No  5. What are the other ma...
ICT/2022/139 R.S.R. Ranathunga   Tutorial 01 1) Print message “Hello World”.  1. What output do you need to generate? A message “Hello World”  2. What input do you have/ need? No  3. What form will it be in? No  4. Will the program have a list of tasks that needs to be done repeatedly (LOOP)? No  5. What are the other major tasks of the program?  Display “Hello World”  2) Print your Curriculum Vitae.  1) What output do you need to generate? Curriculum Vitae  2) What input do you have/ need? Name, Age, Address, Contact number, Educational details  3) What form will it be in? Name as text, Age as integer, Address as string, Contact number as integer, Educational details as string  4) Will the program have a list of tasks that needs to be done repeatedly (LOOP)? No  5) What are the other major tasks of the program?  Create the Curriculum Vitae layout  Input Name  Input Age  Input Address  Inpu...
  C Operators Operators and Operands Operands    Operands are numerical, text and Boolean values that a program can manipulate and use as logical guidelines for making decisions. Operators are used to manipulate and check operand values. If the operator manipulates one operand it is known as unary operator; if the operator manipulates two operands, it is known as binary operator and if the operator manipulates three operands, it is known as ternary operator. C has following operators   Arithmetic operators  all are binary operators  Logical operators  all are binary operators  Relational operators  all are binary operators  Bitwise operators  all are binary operators except ! and ~  Increment, decrement operators  unary operators  Assignment operators  binary operators  Conditional operator  ternary operator  Type cast operator unary operator  sizeof operator  unary operator  Comma operator  binary op...
  Type Casting, Command Line Arguments and Defining Constants Type Casting   • Type cast is an instruction to the compiler to convert one type into another. • For example, if you want to store a 'long' value into a simple integer then you can type cast 'long' to 'int'. • You can convert the values from one type to another explicitly using the cast operator as follows: (type_name) expression • When a cast involves a narrowing conversion, information might be lost.  • For example, when casting a long into a short, information will be lost if the long’s value is greater than the range of a short because its high-order bits are removed. EX:- #include  int main()  {  int sum = 17, count = 5;  double mean; mean = sum / count;  printf("Value of mean : %f\n", mean );  return 0; } #include int main() { int sum = 17, count = 5; double mean; mean = (double) sum / count; printf("Value of mean : %f\n", mean );  return 0;  } Command Line...
 Variables and Data Types Keywords / Reserve Words  • Keywords are predefined, reserved words used in programming that have special meanings to the compiler. C is a case sensitive language, all keywords must be written in lowercase. Identifiers  • An identifier in C consists of a sequence of letters, digits, or underscore characters. However, if you give meaningful name to an identifier, it will be easy to understand and work on for you and your fellow programmers. Rules for writing an identifier - A valid identifier can have letters (both uppercase and lowercase letters), digits and underscores.   The first letter of an identifier should be either a letter or an underscore.  However, it is discouraged to start an identifier name with an underscore.  There is no rule on length of an identifier.  However, the first 31 characters of identifiers are discriminated by the compiler. Variable   • Programming language enable you to assign ...
  Introduction to C Programming Compiling Programs To support a higher-level language, a special computer program must be developed that translates the statements of the program developed in the higher-level language into a form that the computer can understand—in other words, into the particular instructions of the computer. Such a program is known as a COMPILER .  Editing - First write your program using text editor or Integrated Development Environment (IDE). Then you need to save your file by giving a suitable name with “.c” file extension.  Ex :- MyFirstProgram.c Compiling - is the conversion of human-readable source code in a programming language like C into machine code or intermediate code that can be executed by a computer. Linking-After the program has been translated into object code, it is ready to be linked. The purpose of the linking phase is to get the program into a final form for execution on the computer. Debugging - This is known as ...
  Pseudocodes • Another formal program design tool.  • It was developed along with the structured programming.  • Pseudocode works very well with the rules of structured design and programming. Rules for Pseudocode   • Write only one statement per line.  • Capitalize initial key word.  • Indent to show hierarchy.  • End multiline structures.  • Keep statements language independent. Storing and Accessing Data • When we say READ name, hours worked, hourly rate, we are saying that we want the computer to go out to some external input device and retrive three values.  • These values will be stored in the computer's memory,  • Each memory location has an address, and we could use that memory address as the way we refer to the value when giving instructions to the computer. EX:- We could say, READ a numeric value, store it at address 61253.  We could tell the computer to multiple the values at addresses 61253 and 67952 and store t...
Image
  Flow Charts and Design Structures Flow chart is a symbol-oriented design system that identifies the type of statement by the shape of the symbol containing the statement. These symbols are connected by flow lines that show the flow of control through the program. Flow Lines -Representing using arrow. ▫ It shows the flow control through the program. Terminal Symbol - It is used to indicate beginning and end of a subsection within the flowchart, known as a module. Input Output Symbol - It is used to indicate both input (READ) and output (WRITE).  Process Symbol - Indicates using a rectangle and represents calculations and initialization of memory locations. Preparation Symbol - This symbol is used for any initialization done, usually at the beginning of a program.  Decision Symbol - The diamond either asks a YES/NO questions OR makes a True/ False statement. Connector - This is used to connect the flow chats to represent its’ continuation. Basic Design Struct...
  Program Development Cycle Review the Specification-In this phase, we define the problem statement and we decide the boundaries of the problem. Informal Design-Addresses WHAT need to be done. The informal design step lets you make changes in your plan before you invest too much time in one approach. There are two steps in the informal design that need to be completed frequently in a repeated cycle. List the major tasks  & List the subtasks Formal Design-Formal design addresses HOW it will be done. Formal design is a communication tool for program designers and coders. There are many possible program design tools available and this course will concentrate on two of them namely; Flowcharts and Pseudocodes.   Desk check the design. Desk checking is the way to check the logic of the design. Code & Compile-Coding the program is simply translating each design statement into the proper syntax for the desired programming language. using programming languages ...
  What is a Computer ?   • A computer is a machine which can take instructions (data) as input, perform computations based on those instructions (process) and generate results output (information). What is Processing?  • A computer uses a Central Processing Unit or CPU to do all its decision-making and data processing.  • The CPU has an internal set of instructions it follows when it receives a command (Machine Language). • Processing data through computers is  ▫ Fast (Computers processing speed is measured in MIPS - Millions of Instructions Per Second.  ▫ Highly accurate • The CPU follows the programmer's logic to process the data given it.   Machine Language  • Machine Language is the only language that is directly understood by the computer.  • It does not needs any translator program.  • The only advantage is that program of machine language run very fast.  • Each different type of CPU has its own unique machin...