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

1 answer below »
All the knowledge should relate to the textbook"c++ early objects ninth edition" written by Gaddis, Walters and Muganda


Microsoft Word - BCS230_Lab5_handout.docx Lab05-BCS230,M.Alrajab 1 BCS230 Lab5HandoutandAssignment This lab handout provides 3 tasks that students are required to attempt during lab session. Lab objectives are for students to practice with: - Arrays. - Object-Oriented Analysis and Design. Task1: The following skeleton code accepts 20 inputs as test scores for students and stores them in an array. The scores should be between 1 and 100 (perfect score). In its current form, the program reads the values from the user and then prints nothing. Step1: Create a project and then run the following skeleton code. Step2: Modify the code so that, in addition to what it does, it will: • Print all the elements of the array. • Print the average score. • Change the fixed number of inputs (currently 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: 4 9 2 15 2 5 7 15 8 1 6 15 15 15 15 15 Write a program that simulates a magic square using a two-dimensional 3x3 array. It should have a Boolean function isMagicSquare that accepts the array 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 array that is a magic square and one that is not. Task3: 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 array. Ø 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. AssignmentLab5 Whattohandin WriteaprogramthatallowstheusertoconvertanyintegernumbertoRoman numeralandtheotherwayaround. - Youshouldcreateandprintamenuthatallowstheusertoselecteither RomantoIntorInttoRoman. - Ifoneoptionisselectedthenyoushouldpromotetheusertoenterthe numberandthenyouprinttheequivalenceintheothersystem. - Validateinput,i.eRomannumeralsshouldbegreaterorequalI. - Repeatuntiltheuserenter-1(mainmenu). • Youshoulduseatleastoneclass(.hand.cpp). • Testyourcodebeforesubmission. • SubmityourcodebeforeTuesdayMarch/06@11:59pm • ThesubmissionpagetobeavailabletillFridayMarch/09th11:59pm with-10%penaltyperday.
Answered Same DayMar 01, 2020BCS230

Answer To: Microsoft Word - BCS230_Lab5_handout.docx Lab05-BCS230,M.Alrajab 1 BCS230...

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();
break;
case 2:
converter.integerToRoman();
break;
case -1:
break;
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 error = false;
int nIndex = 0;
num = 0;
while( (error == false) && (nIndex < length) )
{
switch(romanNum[nIndex])
{
case 'M':
num += 1000;
if(previous < 1000)
{
num -= 2 * previous;
}
previous = 1000;
break;
case 'D':
num += 500;
if(previous < 500)
{
num -= 2 * previous;
}
previous = 500;
break;
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