Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Microsoft Word - BCS230_Lab5_handout.docx Lab05 - BCS230, M. Alrajab 1 BCS230 Lab5 Handout and Assignment This lab handout provides 3 tasks that students are required to attempt during lab session....

1 answer below »
Microsoft Word - BCS230_Lab5_handout.docx
Lab05    -    BCS230,    M.    Alrajab         1    
BCS230    
Lab5    Handout    and    Assignment    

This lab handout provides 3 tasks that students are required to attempt
during lab session.
Lab objectives are for students to practice with:
- A
ays.
- Object-Oriented Analysis and Design.
    
    
    
    
Task1:        
    
The following skeleton code
accepts 20 inputs as test scores for
students and stores them in an
a
ay.
The scores should be between 1
and 100 (perfect score). In its
cu
ent form, the program reads
the values from the user and then
prints nothing.

Step1: Create a project and then
un the following skeleton code.

Step2: Modify the code so that, in
addition to what it does, it will:

• Print all the elements of the a
ay.
• Print the average score.
• Change the fixed number of inputs (cu
ently 20 test scores) to be any
positive number between 1 and 50.
• Create and use a function that counts how many scores are perfect.
• Count and report how many scores are less than 59.



Lab05    -    BCS230,    M.    Alrajab         2    
Task2:    

The magic square is a grid with three rows and three columns that has the
following properties:

• The grid contains the numbers from 1 through 9 exactly.
• The sum of each row, each column, each diagonal all add up to
the same number. This is shown in the following:


XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX

Write a program that simulates a magic square using a two-dimensional
3x3 a
ay. It should have a Boolean function isMagicSquare that accepts
the a
ay as an argument and returns true if it determines it is a Magic
Square and false if it is not. Test the program with one a
ay that is a
magic square and one that is not.





Task    3:        

Write a program that displays the Roman numerals
equivalent of any decimal number between 1 and 20 that
the user enters.

Step1:
Ø First store the Roman numerals in an a
ay.
Ø Create a function that allows you to enter the integer numbers from
1-20.
Ø Print the Roman numeral value of the entered integer.
Ø Loop to allow the user to continue entering numbers until an end
sentinel of 0 is entered.

Roman Integer
I 1
V 5
X 10
L 50
C 100
D 500
M 1000
Lab05    -    BCS230,    M.    Alrajab         3    



Step2:
Ø Redesign your program based on OOP principles so that you create
a class called IntRomanType (with header and source).
Ø Create a member function that converts any integer from 1 to 5000
to Roman numerals.
Ø Test your class using main function (you should have three files:
IntRomanType.cpp, IntRomanType.h and main.cpp).
Ø Loop to allow the user to continue entering numbers until an end
sentinel of 0 is entered.


Step3:
Ø Put together the code from lab04-task2 and this task-step2 to make
a program that converts a number both ways. You need to provide
a menu for the user to select either R2I (Roman to Integer) or I2R.
Menu design should include screen control such as clearing the
screen before printing.

    
Assignment    Lab5    
What    to    hand    in    
    
Write    a    program    that    allows    the    user    to    convert    any    integer    number    to    Roman    
numeral    and    the    other    way    around.    
    
- You    should    create    and    print    a    menu    that    allows    the    user    to    select    either    
Roman    to    Int            or                Int    to    Roman.    
- If    one    option    is    selected    then    you    should    promote    the    user    to    enter    the    
number    and    then    you    print    the    equivalence    in    the    other    system.    
- Validate    input,    i.e    Roman    numerals    should    be    greater    or    equal    I.    
- Repeat    until    the    user    enter    -1    (main    menu).    
    
• You    should    use    at    least    one    class    (.h    and    .cpp).    
• Test    your    code    before    submission.    
• Submit    your    code    before    Tuesday    March/06    @    11:59pm    
• The    submission    page    to    be    available    till    Friday    March/09th    11:59pm        
with    -10%    penalty    per    day.
Answered Same Day Mar 01, 2020 BCS230

Solution

Snehil answered on Mar 05 2020
136 Votes
lab5.cpp
#include "lab5.h"
#include using namespace std;
int main()
{
Converter converter;
int option;
do
{
cout
"1. Roman to int";
cout
"\n2. Int to roman";
cout
"\nEnter your choice (-1 to exit) : ";
cin
option;
switch(option)
{
case 1:
converter.romanToInteger();

eak;
case 2:
converter.integerToRoman();

eak;
case -1:

eak;
default:
cout
"Invalid option\n";
}
}while(option!=-1);
return 0;
}
Converter::Converter()
{
romanNum="I";
num=1;
romanSymbols = "IVXLCDM";
= {'I','V','X','L','C','D','M'}
}
void Converter::romanToInteger()
{
setRoman();
int length = romanNum.length();
int previous = 0;
bool e
or = false;
int nIndex = 0;
num = 0;
while( (e
or == false) && (nIndex < length) )
{
switch(romanNum[nIndex])
{
case 'M':
num += 1000;
if(previous < 1000)
{
num -= 2 * previous;
}
previous = 1000;

eak;
case 'D':
num += 500;
if(previous < 500)
{
num -= 2 * previous;
}
previous = 500;

eak;
case 'C':
num += 100;
if(previous < 100)
{
num -= 2 * previous;
}
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here