Search
Log in
Latest topics
Statistics
We have 30 registered usersThe newest registered user is deigavr
Our users have posted a total of 191 messages in 126 subjects
Who is online?
In total there are 2 users online :: 0 Registered, 0 Hidden and 2 Guests None
Most users ever online was 125 on Wed Apr 07, 2021 9:18 am
2nd lab of 2nd semister
Page 1 of 1
2nd lab of 2nd semister
Lab # 2
Objective
Basic Programming review on variables, switch statement, Iteration constructs, arrays,
strings.
Theory
Variables
“A variable is a space in the
computer’s memory set aside for a certain kind of data and given a name for
easy reference.”
Variables may be the most
fundamentals aspect of any computer language. Variables are used so that the
same space in memory can hold different values at different times. For
instance, suppose you are writing a program to calculate someone’s paycheck,
you will need to store at least the hourly rate and the hours worked. If you
want to do the calculation for more than one employee, you will need to use the
same program and the same spaces in memory to store similar data for additional
employees. A variable is a space in memory that plays the same role many times,
but may contain a different value each time.
Switch Statement A switch statement is a type of control statement that exists in most modern imperative programming languages (e.g., C, C++, C#, and Java). Its purpose is to allow the value of a variable or expression to control the flow of program execution. In some other programming languages, a statement that is syntactically different but conceptually the same as the switch statement is known as a case statement or a select statement.
For Loop
“A for loop is a programming language statement which allows code to be repeatedly executed. A for loop is classified as an iteration statement.”
The for loop is almost universally held to be the most commonly
used loop. This is extremely useful when you have to execute a given set of
instruction a limited number of times with little or no changes. This loop will
start with giving a variable a predefined value and then keep on executing the
body part of the loop as long as the given condition is true. Every time the
loop is executed, the variable gets a new value.
Arrays “A capability that enables the user to define a set of ordered data items known as an array.” An array is a data structure consisting of a group of elements that are accessed by indexing. In most programming languages each element has the same data type and the array occupies a contiguous area of storage. Arrays can be classified as fixed-sized arrays (sometimes known as static arrays) whose size cannot change once their storage has been allocated.
Strings
“A string is a contiguous sequence of symbols or values, such as a character string (a sequence of characters) or a binary digit string (a sequence of binary values).” Strings are the form of data used in programming languages for storing and manipulating text String is generally understood as a data type storing a sequence of data values, usually bytes, in which elements stand for characters. A variable declared to have a string data type usually causes storage to be allocated in memory that is capable of holding some predetermined number of symbols. Functions
Task
1.
Take a character letter as input. Check and display
whether the input value is a vowel or not.
2.
Calculate and display the number of days in a given
month using the Switch statement.
3.
Write and run a program that reads an angle (expressed
in degrees) and states in which quadrant the given angle lies. An angle A is
said to be in the
* first quadrant if it is in
the range 0 <= A < 90
* second quadrant if it is in
the range 90 <= A < 180
* third quadrant if it is in
the range 180 <= A < 270
* and fourth quadrant if it is
in the range 270 <= A < 360.
4.
Use nested for loop to calculate the factorial of n.
5.
Write a program that computes and prints the sum of
each column of a 2-D array.
6. Write
a program that asks for user's name and then writes it back with the first name
as entered, and the second name all in capital letters.
Enter your name: Sherlock Holmes Sherlock HOLMES
7. Write
a program that input a string, reverses the string using Function.
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|
Mon Aug 01, 2011 11:44 pm by Guest
» Netbook Brands
Mon Aug 01, 2011 5:39 am by Guest
» backlinks checker backlink service
Sun Jul 31, 2011 8:56 am by Guest
» how to buy facebook fans f4
Sat Jul 30, 2011 2:34 pm by Guest
» Alle bijzondere dingen in de zaanstreek
Sat Jul 30, 2011 8:11 am by Guest
» HERE YOU CAN POST ALL WEBSITE LINKS...
Wed Aug 26, 2009 2:16 pm by onesimpletech
» cool web site for all must check it
Mon Jul 06, 2009 2:32 pm by Snopy Cobra
» poetry spirit
Mon Jul 06, 2009 2:31 pm by Snopy Cobra
» best to learn VC++
Sun May 10, 2009 3:22 pm by Guest