Date post: | 07-Jul-2015 |
Category: |
Documents |
Upload: | rurumedina |
View: | 53 times |
Download: | 0 times |
Rubferd Eric F. Medina
Bm10203
http://eglobiotraining.com.
Final RequirementTo be passed to: Prof. Erwin M. Globio
http://eglobiotraining.com
A Programing language is used to write computerprograms such as application and utilities.
Programing allows a programmer or end user todevelop the sets of instructions that constitute a computerprogram or software. The role of a programing language can bedescribed in two ways:
Technical: It is a means for instructing a Computer to performTasksConceptual: It is a framework within which we organize ourideas about things and processes.
PROGRAMING
http://eglobiotraining.com
As an individual, I have learned that programming is avery broad because it composes many scripts, applications andcan be used to run a program that has been part of theprogramming language.
A programming language should both provide means todescribe primitive data and procedures and means to combineand abstract those into more complex ones.
The distinction between data and procedures is not thatclear cut. In many programming languages, procedures can bepassed as data (to be applied to ``real'' data) and sometimesprocessed like ``ordinary'' data. Conversely ``ordinary'' data canbe turned into procedures by an evaluation mechanism.
http://eglobiotraining.com
At first, programming is confusing because you have somuch to understand about codes that will enable to run aprogram. Programming has applications and programdevelopment, the best example for this is the Internet bowser…
Programming is a creative process done by programmersto instruct a computer on how to do a task. Fundamentallyprograms manipulate numbers and text. These are the buildingblocks of all programs.
Programming languages let you use them in different ways, e.gadding numbers, etc… or storing data on disk for later retrieval.
http://eglobiotraining.com
You have to consider languages to run or write your ownprogram, most demanded language in programming is the DEV C++(a full-featured Integrated Development Environment (IDE)).
C++ is one of the most used programming languages in theworld. Also known as "C with Classes".
New to programming or thinking about it? It might surprise you toknow that there are many programmers who program just for funand it can lead to a job.
Switch case statements are a substitute for long if statements that compare a variable to several "integral" values ("integral" values are simply values that can be expressed as an integer, such as the value of a char). The value of the variable given into switch is compared to the value following each of the cases, and when one value matches the value of the variable, the computer continues executing the program from that point.
http://eglobiotraining.com
The default case is optional, but it is wise to include it as it handles any unexpected cases. Switch statements serves as a simple way to write long if statements when the requirements are met. Often it can be used to process input from a user.
http://eglobiotraining.com
This program will compile, but cannot be run until the undefined functions are given bodies, but it serves as a model (albeit simple) for processing input. If you do not understand this then try mentally putting in if statements for the case statements. Default simply skips out of the switch case construction and allows the program to terminate naturally. If you do not like that, then you can make a loop around the whole thing to have it wait for valid input. You could easily make a few small functions if you wish to test the code.
http://eglobiotraining.com
The switch-case statement is a multi-way decision statement. Unlike the multiple decision statement that can be created using if-else, the switch statement evaluates the conditional expression and tests it against numerous constant values. The branch corresponding to the value that the expression matches is taken during execution.
The value of the expressions in a switch-case statement must be an ordinal type i.e. integer, char, short, long etc. Float and double are not allowed.
The syntax is :
http://eglobiotraining.com
The case statements and the default statement can occur in any order in the switch statement. The default clause is an optional clause that is matched if none of the constants in the case statements can be matched.
Consider the example shown below:
http://eglobiotraining.com
Here, if the Grade is 'A' then the output will be:
http://eglobiotraining.com
This is because, in the 'C' switch statement, execution continues on into the next case clause if it is not explicitly specified that the execution should exit the switch statement. The correct statement would be:
http://eglobiotraining.com
Although the break in the default clause (or in general, after the last clause) is not necessary, it is good programming practice to put it in anyway.
An example where it is better to allow the execution to continue into the next case statement:
http://eglobiotraining.com
Looping Statement!Uses a C Programing Statement
http://eglobiotraining.com
while ( expression )statement
In a while loop, the expression is evaluated. If nonzero, the statement executes, and the expression is evaluated again. This happens over and over until the expression's value is zero. If the expression is zero the first time it is evaluated, statement is not executed at all.do
statementwhile ( expression);
A do while loop is just like a plain while loop, except the statement executes before the expression is evaluated. Thus, the statement will always be evaluated at least once.
for ( expression1; expression2; expression3 )statement
In a for loop, first expression1 is evaluated. Then expression2 is evaluated, and if it is zero EEL leaves the loop and begins executing instructions after statement. Otherwise the statement is executed, expression3 is evaluated, and expression2 is evaluated again, continuing until expression2 is zero.
You can omit any of the expressions. If you omit expression2, it is like expression2 is nonzero. while (expression) is the same as for (; expression; ). The syntax for (;;) creates an endless loop that must be exited using the break statement (or one of the other statements described below).
http://eglobiotraining.com
The for loop construct is used is used to repeat a statement or block of statements a specific number of times.
The while loop construct only contains condition.
The do while, the difference between do while loop and other loops is that in the do while loop the condition comes after the statement
Types of LoopingThat can be use in Programing
http://eglobiotraining.com
The break keyword is used to terminate a loop, intermediately bypassing any conditions. The control will be transferred to the first statement following the loop block. The break statement can be used to terminate an infinite loop or to force a loop to end before its normal termination.
The Breakin Programing
http://eglobiotraining.com
#include<stdio.h>
#include<conio.h>
int main(void)
{
int n;
printf("rank yourself from 1-3: ");
scanf("%d",&n);
switch(n)
{
case 1:
printf("bad");
break;
case 2:
printf("fair");
break;
case 3:
printf("good");
break;
default:
printf("invalid");
break;
}
getch();
return 0;
}
Case 1 & Output
http://eglobiotraining.com
Here, I program that if you type and enter number 1, the computer will answer “bad” but if you use number 2, the computer will answer “fair” and last is number 3, the computer will answer “good” just like in the previous slide.
http://eglobiotraining.com
#include<stdio.h>
#include<conio.h>
int main(void)
{
int n;
printf("1+1+2-3= ");
scanf("%d",&n);
switch(n)
{
case 1:
printf("correct");
break;
default:
printf("wrong");
break;
}
getch();
return 0;
}
http://eglobiotraining.com
Case 2 & Output
Here in case two. If the answer was correct the computer were about to answer “correct” but if your answer is incorrect the computer were program to answer “wrong”
http://eglobiotraining.com
http://eglobiotraining.com
#include<stdio.h>
#include<conio.h>
int main(void)
{
char n;
printf("what is the title of the philippine national anthem?\na)bayang magiliw\nb)lupang hinirang\nc)ang bayan ko ");
scanf("%c",&n);
switch(n)
{
case 'a':
printf("wrong");
break;
case 'b':
printf("correct");
break;
case 'c':
printf("wrong");
break;
default:
printf("invalid choice");
break;
}
getch();
return 0;
}
Case 3 & Output
Here in case 3, I do some choices in the question “what is the tittle of the Philippine national anthem?” the choices are a)Bayang magiliw, b)lupang hinirang or c)Ang bayan ko. The correct answer is letter “B” if you choose the correct letter the computer will answer “Correct” but if you choose a wrong answer the computer will answer “wrong” just like in the previous slide.
http://eglobiotraining.com
#include<stdio.h>
#include<conio.h>
int main(void)
{
int n;
printf("(4+4)x5= ");
scanf("%d",&n);
switch(n)
{
case 40:
printf("correct");
break;
default:
printf("wrong");
break;
}
getch();
return 0;
}
http://eglobiotraining.com
Case 4 & Output
Here in case 4. I use some math question so that the student will think of what is the correct answer. “40” is the correct answer if they got it right the computer will print “CORRECT” but if it is incorrect the computer will print “WRONG”
http://eglobiotraining.com
#include<stdio.h>
#include<conio.h>
int main(void)
{
char n;
printf("choose a shape:\ncircle\nrectangle\ntriangle ");
scanf("%c",&n);
switch(n)
{
case 'c':
printf("Area=(3.1416)(r)(r)");
break;
case 'r':
printf("Area=(length)(width)");
break;
case 't ':
printf("Area=1/2(b)(h)");
break;
default:
printf("invalid");
break;
}
getch();
return 0;
}
http://eglobiotraining.com
Case 5 & Output
In the last case, 5. I program the computer to answer the right area of a given shape. Just like in the previous slide if you choose circle the computer will answer “3.1416(r)(r)” so as if you choose other shape.
http://eglobiotraining.com
#include<stdio.h>
#include<conio.h>
int main(void)
{
int ctr;
for(ctr=-10;ctr<=10;ctr++)
{
printf(" %d",ctr);
}
getch();
return 0;
}
http://eglobiotraining.com
Loop 1 & Output
The value of ctr is equal to -10 if the ctr is less than or equal to 10. the computer will print so on and so forth
http://eglobiotraining.com
#include<stdio.h>
#include<conio.h>
int main(void)
{
int ctr;
for(ctr=5;ctr<=50;ctr=ctr+5)
{
printf(" %d",ctr);
}
getch();
return 0;
}
http://eglobiotraining.com
Loop 2 & Output
The value of ctr is 5 if the ctr is less than or equal to 50 then the value of ctr that is 5 will become 10 because the program will add another 5 and again and again and again.
http://eglobiotraining.com
#include<stdio.h>
#include<conio.h>
int main(void)
{
int n=2;
while(n<=100)
{
printf(" %d",n);
n=n*2;
}
getch();
return 0;
}
http://eglobiotraining.com
Loop 3 & Output
The value of n is 2 if the n is less than or equal to 100 then the value of n that is 2 will become 4 because the program is to be multiplied by 2.
http://eglobiotraining.com
#include<stdio.h>
#include<conio.h>
int main(void)
{
int n;
n=4;
do
{
printf(" %dth",n);
n++;
}while(n<=13);
getch();
return 0;
}
http://eglobiotraining.com
Loop 4 & Output
The value of n is 4 if the n is less than or equal to 13 then the value of n that is 4 will become 5. the computer will just add 1 to n which is 4.
http://eglobiotraining.com
#include<stdio.h>
#include<conio.h>
int main(void)
{
int a;
a=1;
do
{
printf(" %d %d",a,a);
a++;
}while(a<=9);
getch();
return 0;
}
http://eglobiotraining.com
Loop 5 & Output
http://www.slideshare.net/rurumedina/fundamentals-of-prog-by-rubferd-medina-14685584
The value of a is 1 if the a is less than or equal to 9 then the value of a that is 1 add 1. it will be repeated and the next is the other number. Just like in the previous slide.
http://eglobiotraining.com
This file is to be submitted by:Prof. Erwin M. Globiohttp://eglobiotraining.com/