Sei sulla pagina 1di 16

for Univirsty Services

Mid Term Revision

www.student-center.alafadl.net
Imp/e :-

A company produces two types of TVs (Type 1 and Type 2), each type has
different sizes as shown in table below. Write a program to enter the TV type (
1 or 2 ), the TV size, and TV price before discount, then calculate its final price
after applying the discount and adding a transportation cost .. The user is not
allowed to enter wrong type

Type Size Discount Transportation Cost


Size < 20 3% 10$
1 20 S Size < 30 7% !;?$
Size ~ 30 9% .(:;t$:~"
Size < 20 10%
2 20 S Size <: 30 12%
¥ii~::>:,20
~ ....
~;~:?1 15%

. M~duie M~iflH~~~ti11I~!!)?
... (::Y:t:</::::::~.,.

~tiiifl1i;fjl~:
~~~.Maon () A{? sf;~1Isinteger \ii
l,.•..•..•..
:'.:.:.:,·:·
..
•..

:.::.·
..
::::.::::
•....
::
:•.::
:•.::
......
... .' :1: ,..:..:..:.:.:..:, .
.
'iV)6im price, newprice As single "'0

If Size < 20 Then,

Case 2
If Size < 20 Then ..,.,.,.,.-

Newprice = 0.9*price + 20

Else if Size >= 20 and Size < 30 Then -


t~1I .••."'.<,j.~;..-•••..~"' •..•,.,,.'._. •••. ...,~. ,•••. _L ..'.....;.:. •. •• ~. ,,.. •• _,:.~ ••••• ·.,· __ • ••• ·.f.:...'-n·', •.•,;...1••. 'J • .:.,...... .·~~,,,pi.~· ..••.::-..;..lO_.:h:•._.~~,,,.,_~ •• ,·._.:_~ .•. .:.:.~._..:.~ ••;.. •.,.-,;.:,<~.·~·~_, ..•.':.--c •••••• _i,;,AI~.k." •••.
'...•••-"'~"~~"'~ ~..• ,..•.••.•••
,.• ,,__ .. r _. ,~.:.. ;;
...~----------------------------------------------~-----------,
Newprice = 0.88*price +25

Else

Newprice = 0.85*price + 30

End If

Case else

Msgbox (" Wrong entery")

GotoX

End Select

Msgbox (" the final Price = II & newprice)

'.~n::::~~le", .G,~g" J:>. ,.'. (,ilt::!!illi;:h .


..'"!~j[,,~l::~'~i~,~~J}:~:i~~~
Ise e oleprog~~!!~I.;ill;i'::~rll'~~'::~;:li;:~;!:;>
if in th wh
·ModuleM6aulet'~·" ::::.~:~.1:~.:.·,}/· .:.:';';';~':':';':':';':';':':':':'"
.......'...~ ~ -·::;;;~~i~~}I~~m~t';:·:;~:}~:~~~~:!·~··
c

Su b ~'!!:::(;::~',':lJ'jj>'
\:il,:~:t:;~itt;H;::~~:::e:;~:~~f.rice,,)(~II;!i~l,::::;:>
u' :i;e S~,!~!'jIJ,I,l!ib
= lnputbox (" Enter the

Type = Inputbox (" Enter the.~1v:p.~n>:"


-,':';;;({}::'" •

/:> -,

-,,

Newpriqf~:,>Q~:Amce + 20

Else if s;;~~;t~!~iji~d Size < 30 Then

Newprice = 0.88*price +25

Else

®
--- -=--
~wprice = 0.85*price + 30

End If

Else

Msgbox (" Wrong entery")

Go to X

End Select

Msgbox (" the final Price = II & newprice )

End sub

. End module

>:;'"
~'.',.

"::::.>.:-.. Ai~r.>·:·...:,~ize Discdijrif\ -, ··':, Traij~p.Q:rtij.n~n<:;.


~";1lJ"Y . Site S 10 ~:>.. 5 %··::<{t\~:~ ·'::;~fm<~.'${{{{W
10 < Size :s; 20 \~:[:im~::7:%.i,..::;;;;:;:[:::!f~>:;::::::)):)~!~!$.
20 < Size :s; 30
Size> 30

- ....)~" GoTo
Jmple :-

A factory has three types of workers asfollowing :-

Type Hour price Over Tax Money/absence day


1 6$ 300 8% 15$
2 4$ 200 6% 10$
3 2$ 100 3% 5$
Write a computer program to enter worker type, work hours and his
absent days then calculate his net salary. The user is not allowed to
enter wrong type.

. Solution

........•..,--,- - .-'~ ;..,- :. -; -'~ .: ;; ~""---' ."" -. '-. .,' •.. ~"~'~ ,,'

--
1- Using Select Case Statement

2- Try these Programs

Using simple if statement, Calculate the net Salary of the workers

Type Hour price Over Tax

l;~:' 2,3 r~:;::J}J{)$ 150


~!!!l..-.,.-..-....;~t;,:....-- .l@J
.....'.....
30$ 200
40$

Calcu'ate<tft~.,Il¢'f'·'Sa'aryof
"'i:~:~'::/
the work~i~/Jh~. pfpgta1iftn(iit;t~.att~rker
~::::::::::;::::::::::::::::::::;:;,
'!'::::::::::;:" )::::::::::::~~I "':'~::::::::~:;>.. -",,:::.::.,
na'n:g then pHrrt in a suitable form thgwatt(er nahil*h~6dAts.":S:at~f:y.

!i;];"",,::fY' '''~umber of day~~;:;~;i;.>, ,,;":~:~;~::'j'"


Less than 7 days\UU>::{t::;;:-. r{i}it:/)m!?{itoo
..-;::.:
ample :-

Write a program to enter the worker work hours and the hour price then
calculate the worker net salary. If the work hours exceeds 40 hours, the
extra hours will be as twice in price asthe normal hours.

Solution

Module Module!

Sub Main ()

Dim Price, Hours, Ex_Hours, Salary As Single

Hours = Inputbox (" Enter worker hours")


•...
~-."":-:.
Price = Inputbox (" Enter the hour price")

:;:~~;~;~~~;ij;;>
E1(:::Hour.-&,;;:
Hour.s::~~O

s.,

'i(;t\M:;;;h
...
.ample :-

Write a program to enter the student degrees in 10 subjects then print


his grade, the user is not allowed to enter wrong degree.

Percentage Grade
Percentage < 50 Fail
50 ~ Percentage < 65 Pass
65 s Percentage < 75 Good
75 s Percentage < 85 Very good
Percentage ~ 85 Excellent
Solution
'=:"

;"Module -Moduief~Y \):::;:::tJ~)


Sub Main 0
r:~:!
::::::,
::;::::i:""'"
.i:::::::~
.~::~~:.\:l:!;!:~~:{I}!I~~::;:;:;:;:;:d)J;/
Dirii=:ttegre'e'~;Sum P.~r.;;Assingle

Oi*tradiif~~},j/

\fi~:T:~:~~}r~~
i(Iri*t 1
r;:::;::;:::::;:;;.-
\;:;;.;. \~}>"i~lJ~!!!I~!;.:.·
' •.. .
---·_:··:.:.l.;.: ..:: •.. :; •.:.:,: .....: ..:.:.::.: .....

Degree = Inputbox ("Enter degree'(·~Jf/}:::;;· -,

Next

Per = Sum / 10 ,<r:IJ:i}:::;::>:.


If Per < SO Then

Else if Per >= so q:na.per.;;!:!6s,,·Tti'~t.f::::::>,


.....
,;;(::::::>::::)

grade = " Excell'ertt!~(t~{i

End if

Msgbox (" The grade is" & grade)


, End Sub

. End Module
1- Repeat the last program using Select case

2- If he add a condition that the student should pass in all

subjects.

..·.-":.·.1 •

-..•..
..~.. -
',"

.I~~"J

.:::::::::::~:-.

/;::::~;::::::'P'

®
.ample :-

Write a computer programto simulate the following circuit.


Sa. ~'-

~~~'3~1
cp _____________
f~'
I

Solution

. Mocfule-Modulel

5ub Main t,11::j ~IlI;;:~-:;~~;f~:i:i:!~>


r-):! :::::::~.,"'
Dim \l/~1IR2(.R.~I.Rt,I~;JZiI3 As Single
,..•.~\ ~~.::;::~::::::'}: ::::~::~~:.::,:;;;;;:::;:;;.~~::~;:::.~f
Dffu?sl'::,st;:/i;s"I nte~e:b"
.;;:::::\ '~r:~~.. :::~~~:::~~;~;:-
•.
V-~"lnpul.Qpx. ('~::mtE:~rthe voltage")
":'~:t~:;::::)~
Rl ~Jm~utb,~KW Enter the first resistan~~~:l:::::::::",.

\". RZ =;~,~~~~r~:.
Enterthe s~cond:esis~,~~,~~;i;j
i:?::<~J;==1,mw.tbo~J Enter the Third reslstance:::::):}:::-:::-

\;;ill;~~:::::::::T::::: :~::: \Ji;:;',{i,{!:i;),>.


IF 51 = 0 and 52 = 0 Then ";i!j]:tU:ft.
11=0

12=0

13=0 <;~:?t~::::"

11 = V I Rt

12= 11 * R3 t:t~~,:~:~~J\
13= 11-12 '<':;;:::ff:i):i~~~[~~~~f~[[)
End If

Msgbox (" The Three Currents are" & 11& 12 & 13)
~ End Sub

~ End Module
~
N I
I

-I
~
-e
f'+
o
_.
I/)

3
-
s::
QJ
f'+
Ci)
-I
'::T
Ci)
.1/)
ro
Q
~
n
C
f'+
I/)
.' 1m pie :-

Write a program to enter 10 numbers then calculate the maximum and


minimum numbers

Solution

- Module Modulel
Sub Main ()

Dim I, Num , Max, Min As Integer

Num = Inputbox (" enter the first number ")

Max = Num ~':"

\)]]):»:.J::" ..

End If

Next

. End Sub

@
. ' . 'Jmple :-

. Using Select Case Statement, Write a program to simulate a simple


calculator, the user is not allowed to enter wrong operation.

Solution
-. ~ , ..-.-
Module Module!

Sub Main 0
Dim Numl, Num2 as Integer

Dim result as Integer

Dim Op as String

Numl = Inputbox ( II Enter the first number ")

Num2 = Inputbox ( II Enter the second number ")

Case" /"

result = Numl / Num 2

End Select

.'. "" .; ••.••••• " ,~, ', •.•••••• , ••.• ~ .••. - 'co '. ", ~_'. . •••. _, ., "" "" '.'~ .~,. ~¥.' •• _

1- Using IF Statement
2- He can determined the operators as follow
( * , mod, / , \ , + , 1\ )
· -' ample :-

Write a program to calculate factorial of number n positive number, to


take into consideration the following cases:

O! = 1, 1! = 1, -ve number is not valid so that the program give an error


message and return to enter Valid value

Solution
Module Modulel
Sub Main ()
Dim I, n, fact As Integer
X: ~';"

N = Inp.~,tbox
::·;:;:1
( " Ent~Hh:gv.qlue
:;::::.:::::::::::::::;~.{'
of integer number" ) \a!i~~~~>:',J:~':_
If n <i&Then 'fri':>':'
.' Jmple:-

Write a computer program to calculate the roots of 2nd order equation

Solution

~.Module Modu~Jel

Sub Main 0
Dim a, b, c, d, Xl, X2 As Single
a= Inputbox ( " enter the value of coefficient a ")
b= Inputbox ( " enter the value of coefficient b ")
c= Inputbox ( " enter the value of coefficient c " )
d=bI\2-4*a*c ~':-.

if d 1~Then ~);-':lt>
Msg~px ( " imaginal!y:r.oots " )
\l;j~f~~~>:',J:~':.

I,

< End Sub


. End Module
· .~. Examples

1- Write a computer program to print even numbers between 0 &

100

2- Write a computer program to print odd numbers between 0 &

100

Potrebbero piacerti anche