100% tevredenheidsgarantie Direct beschikbaar na je betaling Lees online óf als PDF Geen vaste maandelijkse kosten 4.2 TrustPilot
logo-home
Overig

Information Technology Programming Java

Beoordeling
-
Verkocht
-
Pagina's
8
Geüpload op
26-02-2024
Geschreven in
2021/2022

The Internet helped catapult Java to the forefront of programming, and Java, in turn,has had a profound effect on the Internet. The reason for this is quite simple: Java expands the universe of objects that can move about freely in cyberspace. In a network, two very broad categories of objects are transmitted between the server and your personal computer: passive information and dynamic, active programs

Meer zien Lees minder
Instelling
Vak











Oeps! We kunnen je document nu niet laden. Probeer het nog eens of neem contact op met support.

Geschreven voor

Instelling
Vak

Documentinformatie

Geüpload op
26 februari 2024
Aantal pagina's
8
Geschreven in
2021/2022
Type
Overig
Persoon
Onbekend

Onderwerpen

Voorbeeld van de inhoud

INFORMATION TECHNOLOGY
QUESTION 1 (35 MARKS)

Write a function named "reduce" that takes two positive integer arguments, call them "num" and "denom", treats
them as the numerator and denominator of a fraction, and reduces the fraction. That is to say, each of the two
arguments will be modified by dividing it by the greatest common divisor of the two integers. The function should
return the value 0 (to indicate failure to reduce) if either of the two arguments is zero or negative, and should
return the value 1 otherwise.




Answer Code:

#include <iostream>

using namespace std;

long long aga(long long a, long long b)
{
if (a % b == 0)
return b;
if (b % a == 0)
return a;
if (a > b)
return aga(a % b, b);
else
return aga(a, b % a);
}



C2 General

, int reduce(long long& num, long long& denom)
{
long long agaFrac;
if ((agaFrac = aga(num, denom)) != 1)
{
num /= agaFrac;
denom /= agaFrac;
return 1;
}
else
{
return 0;
}
}

int main()
{
long long num, denom;
cout << "Please enter numerator: ";
cin >> num;
cout << "Please enter denominator: ";
cin >> denom;
if (reduce(num, denom))
{
cout << "The Reduced Fraction is " << num << "/" << denom;
}
else
{
cout << "The Fraction " << num << "/" << denom << " cannot be reduced";
}
}

Reduce Fraction Compiler screens




C2 General

, Cannot be Reduced Compiler screens




QUESTION 2 (30 MARKS)

A parking garage charges a R12.00 minimum fee to park for up to three hours. The garage charges an additional
R0.90 per hour for each hour or part thereof in excess of three hours. The maximum charge for any given 24-hour
period is R20.00. Assume that no car parks for longer than 24 hours at a time. Write a program that will calculate
and print the parking charges for each of 3 customers who parked their cars in this garage yesterday. You should
enter the hours parked for each customer. Your program should print the results in a neat tabular format and
should calculate and print the total of yesterday's receipts. The program should use the function calculateCharges
to determine the charge for each customer. Your outputs should appear in the following format:




C2 General

, Answer Code:

#include <iostream>

float calculateCharges( float hours );

float charge;

int main()
{
int customer;
float one;
float two;
float three = 0;
float hours;

for( customer = 1; customer <= 3; customer++ ) {
printf( "Please Enter customer %d parking hours: ", customer );
scanf( "%f", &hours );

if( customer == 1 )
one = hours;
else if( customer == 2 )
two = hours;
else
three = hours;
}
printf( "%s%10s%12s", "Car", "Hours", "Charge" );
printf( "\n%d%12.1f%12.1f", 1, one, calculateCharges( one ) );
printf( "\n%d%12.1f%12.1f", 2, two, calculateCharges( two ) );
printf( "\n%d%12.1f%12.1f", 3, three, calculateCharges( three ) );
printf( "\n%s%8.1f%12.1f", "TOTAL", one + two + three, calculateCharges( one ) + calculateCharges( two
) + calculateCharges( three ) );
}

float calculateCharges( float hours )
{
int h = hours;
charge = 12.0;

if( hours > 0 ) {
if( hours <= 3 )
return charge;

else if( hours <= 24 ) {
while( h > 3 ) {
charge += .90;
h--;
if( charge >= 20 )
charge = 20;
}
return charge;
}
}


C2 General
$3.09
Krijg toegang tot het volledige document:

100% tevredenheidsgarantie
Direct beschikbaar na je betaling
Lees online óf als PDF
Geen vaste maandelijkse kosten

Maak kennis met de verkoper
Seller avatar
InfoTech

Maak kennis met de verkoper

Seller avatar
InfoTech RichField
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
0
Lid sinds
1 jaar
Aantal volgers
0
Documenten
11
Laatst verkocht
-

0.0

0 beoordelingen

5
0
4
0
3
0
2
0
1
0

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Veelgestelde vragen