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 is 1 user online :: 0 Registered, 0 Hidden and 1 Guest None
Most users ever online was 125 on Wed Apr 07, 2021 9:18 am
1st lab of 2nd semiter
Page 1 of 1
1st lab of 2nd semiter
Lab # 1
Objective
Introduction to Object Oriented Programming.
Theory
“Object-oriented programming
(OOP) is a programming language that uses objects and their interactions to design
applications and computer programs.”
The first step in OOP is to identify all the
objects you want to manipulate and how they relate to each other, an exercise
often known as data modeling. Once you've identified an object, you generalize
it as a class of objects and define the kind of data it contains and any logic
sequences that can manipulate it. Each distinct logic sequence is known as a
method. A real instance of a class is called an object or, in some environments,
an instance of a class. The object or class instance is what you run in the
computer. Its methods provide computer instructions and the class object
characteristics provide relevant data. You communicate with objects, and they
communicate with each other with well-defined interfaces called messages.
The concepts and rules used in object-oriented programming
provide these important benefits:
- The
concept of a data class makes it possible to define subclasses of data
objects that share some or all of the main class characteristics. Called
inheritance, this property of OOP forces a more thorough data analysis,
reduces development time, and ensures more accurate coding. - Since a
class defines only the data it needs to be concerned with, when an
instance of that class (an object) is run, the code will not be able to
accidentally access other program data. This characteristic of data hiding
provides greater system security and avoids unintended data corruption. - The
definition of a class is reuseable not only by the program for which it is
initially created but also by other object-oriented programs.
Task
- Write a program that calculates the area of a circle
from its radius. The radius will be an integer read in from the keyboard.
- Ohm's law relates the resistance of an electrical
device (like a heater) to the electric current flowing through
the device and the voltage
applied to it. The law is:
I = V/R
Here, V is the voltage (measured
in volts), I is the current (measured in amps), and R is the resistance
(measured in ohms.) Write a program that asks the user for the voltage and the
resistance of a device. The program will then write out the current flowing
through it.
- Given
an initial deposit of money, denoted as P, in a bank that pays interest
annually, the amount of money at a time N years later is given by the
formula:
Amount = P*(1 +
R)^N
where R is the interest rate
as a decimal number (e.g., 6.5% is 0.065). Write and run a program that
performs the following steps:
* Reading the values of P and R from the
keyboard.
* Calculating the amount of money that will
be available in 5 years.
* Displaying the result.
- Write
and run a program that reads the name, age, sex, height and weight of a
student and displays with proper heading for each variable.
- Write
a program that adds up the squares and adds up the cubes of integers from
1 to N, where N is entered by the user:
Upper Limit: 5
The sum of Squares is 55
The sum of Cubes is
225
Do this by using just one loop
that generates the integers. Of course, if you really needed to calculate these
sums you would use the appropriate formulas:
12 + 22 + 32 + ... + n2
= n(n+1)(2n+1)/6
13 + 23 + 33 + ... + n3
= n2(n+1)2/4
Add these formulas to your
program and print out their results as well as that of the explicit summations.
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