Sunday, 1 February 2015
Memory
Memory
Computer memory is any physical device capable of storing information temporarily or permanently. For example, Random Access Memory (RAM), is a type of volatile memory that is stores information on an integrated circuit, and that is used by theoperating system, software, hardware, or the user. Below is an example picture of a 512MB DIMM computer memory module.
Volatile vs. non-volatile memory
Memory can be either volatile and non-volatile memory. Volatile memory is a temporary memory that loses its contents when the computer or hardware device loses power. Computer RAM is a good example of a volatile memory and is why if your computer freezes or reboots when working on a program you lose anything that hasn't been saved. Non-volatile memory, sometimes abbreviated as NVRAM, is memory that keeps its contents even if the power is lost. EPROM is a good example of a non-volatile memory.
Memory is not disk storage
It is very common for new computer users to be confused by what parts in the computer are memory. Although both the hard drive and RAM are considered memory, it is more appropriate to refer to RAM as "memory" or "primary memory" and a hard drive as "storage" or "secondary storage" and not memory.
When a program such as your Internet browser is open, it is loaded from your hard drive and placed into RAM, which allows that program to communicate with the processor at higher speeds. Anything you save to your computer such as a picture or video is sent to your hard drive for storage.
When someone asks how much memory is in your computer, it is likely between 1GB and 8GB of Random Access Memory (RAM) and several hundred Gigs of hard disk drive memory (storage). In other words, You will almost always have more hard drive space than RAM.
Memory is the electronic holding place for instructions and data that your computer's microprocessor can reach quickly. When your computer is in normal operation, its memory usually contains the main parts of theoperating system and some or all of the application programs and related data that are being used. Memory is often used as a shorter synonym for random access memory (RAM). This kind of memory is located on one or more microchips that are physically close to the microprocessor in your computer. The more RAM you have, the less frequently the computer has to access instructions and data from the more slowly accessed hard disk form of storage.
Memory is sometimes distinguished from storage, or the physical medium that holds the much larger amounts of data that won't fit into RAM and may not be immediately needed there. Storage devices include hard disks, floppy disks, CD-ROM, and tape backup systems. The term sauxiliary storage, auxiliary memory, and secondary memory have also been used for this kind of data repository.
Additional kinds of integrated and quickly accessible memory are read-only memory (ROM), programmable ROM (PROM), and erasable programmable ROM (EPROM). These are used to keep special programs and data, such as the basic input/output system, that need to be in your computer all the time.
TABLE OF CONTENTS
- Main memory
- Auxiliary memory
- Memory hierarchy
Computer memory, device that is used to store data or programs (sequences of instructions) on a temporary or permanent basis for use in an electronic digital computer. Computers represent information in binary code, written as sequences of 0s and 1s. Each binary digit (or “bit”) may be stored by any physical system that can be in either of two stable states, to represent 0 and 1. Such a system is called bistable. This could be an on-off switch, an electrical capacitor that can store or lose a charge, a magnet with its polarity up or down, or a surface that can have a pit or not. Today capacitors and transistors, functioning as tiny electrical switches, are used for temporary storage, and either disks or tape with a magnetic coating, or plastic discs with patterns of pits are used for long-term storage.
Defining Pseudocode
Defining Pseudocode
Pseudocode is a simple way of writing programming code in English. Pseudocode is not an actual programming language. It uses short phrases to write code for programs before you actually create it in a specific language. Once you know what the program is about and how it will function, then you can use pseudocode to create statements to achieve the required results for your program.
Understanding Pseudocode
Pseudocode makes creating programs easier. Programs can be complex and long. Preparation is the key. For years, flowcharts were used to map out programs before writing one line of code in a language. However, they were difficult to modify, and with the advancement of programming languages, it was difficult to display all parts of a program with a flowchart. It is challenging to find a mistake without understanding the complete flow of a program. That is where pseudocode becomes more appealing.
To use pseudocode, all you do is write what you want your program to say in English. Pseudocode allows you to translate your statements into any language because there are no special commands and it is not standardized. Writing our programs before you code can enable you to better organize and see where you may have left out needed parts in your programs. All you have to do is write it out in your own words in short statements. Let's look at some examples below.
Examples
Create a program to add 2 numbers together then display the result.
Pseudocode
Flowchart
Here are a few more simple examples of pseudocode:
Compute the Area of a rectangle
Compute the Perimeter of a rectangle
Remember, writing basic pseudocode is not like writing an actual coding language. It cannot be compiled or run like a regular program. Pseudocode can be written how you want. But, some companies use specific pseudocode syntax to keep everyone in the company on the same page. Syntax is a set of rules on how to use and organize statements in a programming language. By adhering to specific syntax, everyone in the company can read and understand the flow of a program. This becomes cost effective. That is less time finding and correcting errors.
Basic Guidelines
If you would like to have a format to follow for using pseudocode to create your program, below are some basic guidelines:
Do not use language specific commands in your statements
Pseudocode should be universal. So, when creating the task list you would not include commands that are for any specific language like C++, Java, C#, or Perl. The point of pseudocode is to design a program that can be translated into any language.
Write only one task/statement per line
Make sure you put only one task on each line. Including too much information on one line can be confusing and increases the possibility of errors.
Capitalize Keywords
Capitalizing keywords like Read, Write, or Display helps to show when an action is occurring or when a specific command or process will be necessary when coding in your specific language.
Pseudocode Examples
Pseudocode Examples
Modified 15 December 1999
An algorithm is a procedure for solving a problem in terms of the actions to be executed and the order in which those actions are to be executed. An algorithm is merely the sequence of steps taken to solve a problem. The steps are normally "sequence," "selection, " "iteration," and a case-type statement.
In C, "sequence statements" are imperatives. The "selection" is the "if then else" statement, and the iteration is satisfied by a number of statements, such as the "while," " do," and the "for," while the case-type statement is satisfied by the "switch" statement.
Pseudocode is an artificial and informal language that helps programmers develop algorithms. Pseudocode is a "text-based" detail (algorithmic) design tool.
The rules of Pseudocode are reasonably straightforward. All statements showing "dependency" are to be indented. These include while, do, for, if, switch. Examples below will illustrate this notion.
GUIDE TO PSEUDOCODE LEVEL OF DETAIL: Given record/file descriptions, pseudocode should be created in sufficient detail so as to directly support the programming effort. It is the purpose of pseudocode to elaborate on the algorithmic detail and not just cite an abstraction.
Examples:
1.
If student's grade is greater than or equal to 60
Print "passed"
else
Print "failed"
endif
2.
Set total to zero
Set grade counter to one
While grade counter is less than or equal to ten
Input the next grade
Add the grade into the total
endwhile
Set the class average to the total divided by ten
Print the class average.
3.
Initialize total to zero
Initialize counter to zero
Input the first grade
while the user has not as yet entered the sentinel
add this grade into the running total
add one to the grade counter
input the next grade (possibly the sentinel)
endwhile
if the counter is not equal to zero
set the average to the total divided by the counter
print the average
else
print 'no grades were entered'
endif
4.
initialize passes to zero
initialize failures to zero
initialize student to one
while student counter is less than or equal to ten
input the next exam result
if the student passed
add one to passes
else
add one to failures
add one to student counter
endif
endwhile
print the number of passes
print the number of failures
if eight or more students passed
print "raise tuition"
endif
5.Larger example:
NOTE: NEVER ANY DATA DECLARATIONS IN PSEUDOCODE
Print out appropriate heading and make it pretty
While not EOF do:
Scan over blanks and white space until a char is found
(get first character on the line)
set can't-be-ascending-flag to 0
set consec cntr to 1
set ascending cntr to 1
putchar first char of string to screen
set read character to hold character
While next character read != blanks and white space
putchar out on screen
if new char = hold char + 1
add 1 to consec cntr
set hold char = new char
continue
endif
if new char >= hold char
if consec cntr < 3
set consec cntr to 1
endif
set hold char = new char
continue
endif
if new char < hold char
if consec cntr < 3
set consec cntr to 1
endif
set hold char = new char
set can't be ascending flag to 1
continue
endif
end while
if consec cntr >= 3
printf (Appropriate message 1 and skip a line)
add 1 to consec total
endif
if can't be ascending flag = 0
printf (Appropriate message 2 and skip a line)
add 1 to ascending total
else
printf (Sorry message and skip a line)
add 1 to sorry total
endif
end While
Print out totals: Number of consecs, ascendings, and sorries.
Stop
Some Keywords That Should be Used And Additional Points
For looping and selection, The keywords that are to be used include Do While...EndDo; Do Until...Enddo; While .... Endwhile is acceptable. Also, Loop .... endloop is also VERY good and is language independent. Case...EndCase; If...Endif; Call ... with (parameters); Call; Return ....; Return; When;
Always use scope terminators for loops and iteration.
As verbs, use the words Generate, Compute, Process, etc. Words such as set, reset, increment, compute, calculate, add, sum, multiply, ... print, display, input, output, edit, test , etc. with careful indentation tend to foster desirable pseudocode. Also, using words such as Set and Initialize, when assigning values to variables is also desirable.
More on Formatting and Conventions in Pseudocoding
Do not include data declarations in your pseudocode.
But do cite variables that are initialized as part of their declarations. E.g. "initialize count to zero" is a good entry.
Function Calls, Function Documentation, and Pseudocode
Calls to Functions should appear as:Call FunctionName (arguments: field1, field2, etc.)
Returns in functions should appear as:Return (field1)
Function headers should appear as:FunctionName (parameters: field1, field2, etc. )
Note that in C, arguments and parameters such as "fieldn" could be written: "pointer to fieldn ...."
Functions called with addresses should be written as:Call FunctionName (arguments: pointer to fieldn, pointer to field1, etc.)
Function headers containing pointers should be indicated as:FunctionName (parameters: pointer to field1, pointer to field2, ...)
Returns in functions where a pointer is returned:Return (pointer to fieldn)
It would not hurt the appearance of your pseudocode to draw a line or make your function header line "bold" in your pseudocode. Try to set off your functions.
Try to use scope terminators in your pseudocode and source code too. It really hels the readability of the text.
- Call FunctionName (arguments: field1, field2, etc.)
- Return (field1)
- FunctionName (parameters: field1, field2, etc. )
- Call FunctionName (arguments: pointer to fieldn, pointer to field1, etc.)
- FunctionName (parameters: pointer to field1, pointer to field2, ...)
- Return (pointer to fieldn)
Source Code
EVERY function should have a flowerbox PRECEDING IT. This flower box is to include the functions name, the main purpose of the function, parameters it is expecting (number and type), and the type of the data it returns. All of these listed items are to be on separate lines with spaces in between each explanatory item.
FORMAT of flowerbox should be
********************************************************
Function: ( cryptic text describing single function
....... (indented like this)
.......
Calls: Start listing functions "this" function calls
Show these functions: one per line, indented
Called by: List of functions that calls "this" function
Show these functions: one per line, indented.
Input Parameters: list, if appropriate; else None
Returns: List, if appropriate.
****************************************************************
INDENTATION is critically important in Source Code. Follow standard examples given in class. If in doubt, ASK. Always indent statements within IFs, FOR loops, WILLE loops, SWITCH statements, etc. a consistent number of spaces, such as four. Alternatively, use the tab key. One or two spaces is insufficient.
Use scope terminators at the end of if statements, for statements, while statements, and at the end of functions. It will make your program much more readable.SPELLING ERRORS ARE NOT ACCEPTABLE
******************************************************** Function: ( cryptic text describing single function ....... (indented like this) ....... Calls: Start listing functions "this" function calls Show these functions: one per line, indented Called by: List of functions that calls "this" function Show these functions: one per line, indented. Input Parameters: list, if appropriate; else None Returns: List, if appropriate. ****************************************************************
Pseudocode
Pseudocode (pronounced SOO-doh-kohd) is a detailed yet readable description of what a computer program or algorithm must do, expressed in a formally-styled natural language rather than in a programming language. Pseudocode is sometimes used as a detailed step in the process of developing a program. It allows designers or lead programmers to express the design in great detail and provides programmers a detailed template for the next step of writing code in a specific programming language.
Because pseudocode is detailed yet readable, it can be inspected by the team of designers and programmers as a way to ensure that actual programming is likely to match design specifications. Catching errors at the pseudocode stage is less costly than catching them later in the development process. Once the pseudocode is accepted, it is rewritten using the vocabulary and syntax of a programming language. Pseudocode is sometimes used in conjunction with computer-aided software engineering-based methodologies.
It is possible to write programs that will convert a given pseudocode language into a given programming language
Flowchart In Programming
Flowchart In Programming
Flowchart is a diagrammatic representation of an algorithm. Flowchart are very helpful in writing program and explaining program to others.
Symbols Used In Flowchart
Different symbols are used for different states in flowchart, For example: Input/Output and decision making has different symbols. The table below describes all the symbols that are used in making flowchart
Symbol | Purpose | Description |
---|---|---|
Flow line | Used to indicate the flow of logic by connecting symbols. | |
Terminal(Stop/Start) | Used to represent start and end of flowchart. | |
Input/Output | Used for input and output operation. | |
Processing | Used for airthmetic operations and data-manipulations. | |
Desicion | Used to represent the operation in which there are two alternatives, true and false. | |
On-page Connector | Used to join different flowline | |
Off-page Connector | Used to connect flowchart portion on different page. | |
Predefined Process/Function | Used to represent a group of statements performing one processing task. |
Examples of flowcharts in programming
Draw a flowchart to add two numbers entered by user.
Draw flowchart to find the largest among three different numbers entered by user.
Draw a flowchart to find all the roots of a quadratic equation ax2+bx+c=0
Draw a flowchart to find the Fibonacci series till term≤1000.
Though, flowchart are useful in efficient coding, debugging and analysis of a program, drawing flowchart in very complicated in case of complex programs and often ignored.
Algorithms and Flowchart
Algorithms and Flowchart
Algorithms & Flowchart
1
- In programming, algorithm are the set of well defined instruction in sequence to solve a program. An algorithm should always have a clear stopping point.
- An algorithm (pronounced AL-go-rith-um) is a procedure or formula for solving a problem. The word derives from the name of the mathematician, Mohammed ibn-Musa al-Khwarizmi, who was part of the royal court in Baghdad and who lived from about 780 to 850. Al-Khwarizmi's work is the likely source for the word algebra as well.
- A computer program can be viewed as an elaborate algorithm. In mathematics and computer science, an algorithm usually means a small procedure that solves a recurrent problem.
2
- A flowchart is a formalized graphic representation of a logic sequence, work or manufacturing process, organization chart, or similar formalized structure. The purpose of a flow chart is to provide people with a common language or reference point when dealing with a project or process.
- Flowcharts use simple geometric symbols and arrows to define relationships. In programming, for instance, the beginning or end of a program is represented by an oval. A process is represented by a rectangle, a decision is represented by a diamond and an I/O process is represented by a parallelogram. The Internet is represented by a cloud.
Algorithms
- A sequential solution of any program that written in human language,called algorithm.
- Algorithm is first step of the solution process, after the analysis of problem, programmer write the algorithm of that problem.
- Example of Algorithms:
Q. Write a algorithem to find out number is odd or even?
Ans.
step 1 : start
step 2 : input number
step 3 : rem=number mod 2
step 4 : if rem=0 then
print "number even"
else
print "number odd"
endif
step 5 : stop
Flowchart
1. Graphical representation of any program is called flowchart.
2. There are some standard graphics that are used in flowchart as following:
Figure: Start/Stop terminal box |
Figure: Input/Output box |
Figure: Process/Instruction box |
Figure: Lines or Arrows |
Figure: Decision box |
Figure: Connector box |
Figure: Comment box |
Figure: Preparation box |
Figure: Separate box |
Q. Make a flowchart to input temperature, if temperature is less than 32 then print "below freezing" otherwise print "above freezing"?
Ans.
Figure: Flowchart example of C program |
C Program to Find Transpose of a Matrix
C Program to Find Transpose of a Matrix
This program asks user to enter a matrix (size of matrix is specified by user) and this program finds the transpose of that matrix and displays it.
Source Code to Find Transpose of a Matrix
#include <stdio.h>
int main()
{
int a[10][10], trans[10][10], r, c, i, j;
printf("Enter rows and column of matrix: ");
scanf("%d %d", &r, &c);
/* Storing element of matrix entered by user in array a[][]. */
printf("\nEnter elements of matrix:\n");
for(i=0; i<r; ++i)
for(j=0; j<c; ++j)
{
printf("Enter elements a%d%d: ",i+1,j+1);
scanf("%d",&a[i][j]);
}
/* Displaying the matrix a[][] */
printf("\nEntered Matrix: \n");
for(i=0; i<r; ++i)
for(j=0; j<c; ++j)
{
printf("%d ",a[i][j]);
if(j==c-1)
printf("\n\n");
}
/* Finding transpose of matrix a[][] and storing it in array trans[][]. */
for(i=0; i<r; ++i)
for(j=0; j<c; ++j)
{
trans[j][i]=a[i][j];
}
/* Displaying the transpose,i.e, Displaying array trans[][]. */
printf("\nTranspose of Matrix:\n");
for(i=0; i<c; ++i)
for(j=0; j<r; ++j)
{
printf("%d ",trans[i][j]);
if(j==r-1)
printf("\n\n");
}
return 0;
}
Output
Enter rows and column of matrix: 2 3 Enter elements of matrix: Enter elements a11: 1 Enter elements a12: 2 Enter elements a13: 9 Enter elements a21: 0 Enter elements a22: 4 Enter elements a23: 7 Entered Matrix: 1 2 9 0 4 7 Transpose of Matrix: 1 0 2 4 9 7
Subscribe to:
Posts (Atom)