CSCE 240 – Programming Assignments One to Five solution

$120.00

Original Work ?

Download Details:

  • Name: Assignments-0fy4zz.zip
  • Type: zip
  • Size: 358.26 KB

Category: Tags: , , You will Instantly receive a download link upon Payment||Click Original Work Button for Custom work

Description

5/5 - (1 vote)

CSCE 240 – Programming Assignment One

Program Purpose – Convert numeric values expressed in bases between 2 and 9, inclusive, to
the base 10 equivalents of those values. The program will output the
base 10 values, the number of values input, and the largest value input.
Overview
In a positional numeration system with base b, each position represents a power
of b.
In the decimal system, which is a positional numeration system with base
10, each position represents a power of 10. So, for example, the decimal number
4809 is 4 · 103 + 8 · 102 + 0 · 101 + 9 · 100.
Similarly, in binary, which is a positional numeration system with base 2, each
position represents a power of 2. For example, the binary number 11001 is
1 · 24 + 1 · 23 + 0 · 22 + 0 · 21 + 1 · 20. So, the value 11001 in binary would be
expressed as 25 in decimal.
For more detail and examples about positional numeration systems, read over the
“Numeration Systems” PDF.
Program Details
For each numeric value, the user will enter two integers from the standard input device
(use cin). The first integer is a numeric value, and the second integer is the base in
which that number is expressed.
Your program should check each base input to ensure that it is between 2 and 9,
inclusive. If the base is outside of this accepted range, your program should output
“Base Not Accepted” to the standard output device (using cout), and the program
should end.
Your program should also check each numeric value input to ensure that it only
contains valid digits for the given base. The number of unique digits in a
positional numeration system is equal to the base. In base 10, for example, the
valid digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. The binary numeration system, on
the other hand, only uses the unique digits 0 and 1. If the numeric value input uses
invalid digits, your program should output “Invalid Digit(s) in Number” to the
standard output device (using cout), and the program should end.
If the input numeric value and base are valid, the program should output the number
expressed in decimal (base 10) to the standard output device (using cout)
Following each numeric value entered, the user will input the character ‘y’ if another
numeric value will be input, or ‘n’ if no more numeric values will be input. When the
user enters ‘n’ the program should output the number of values input and the largest
value input (expressed in decimal) in the following format:
Of the num values input, the which value entered (decimalvalue) was the largest
Where num is the number of values input, which is the position of that value (e.g.
“1st”, “2nd”, “3rd”, etc), and decimal is the base 10 equivalent of that value.
Example Input/Output Pairs
Example Input Example Output
1101 1 n Base Not Accepted

Example Input Example Output
1030 3 n Invalid Digit(s) in Number
Example Input Example Output
1101 2 y 13
1101 3 y 37
320 4 y 56
43 5 y 23
11000 2 n 24
Of the 6 values input, the 3rd value entered (56) was the largest
Input Assumptions
Assume that the user input will match the expected format.
i.e.
The user will input integer values, as described above, for the numeric value and
base. If the user enters non-integer values, it is ok (expected) for your program
to crash.
The user will input a single character (y or n as described above) to signify
whether or not another numeric value will be input. If the user enters more than
one character, it is ok (expected) for your program to crash.
Additional Specifications
– All output should be directed to the standard output device using cout.
– All input should be accepted from the standard input device using cin.
– The final output in every execution of your program must be an endl.
– Do not prompt for input.
– All of your source code for the program must be contained in a single file
named program1.cc
– Submit your program1.cc file to the assignment in Blackboard.
– The only header file that can be included in your code is iostream. Programs that
include other headers will not be eligible for correctness points.
– Programs must compile and run on a computer of the instructor’s choosing in the
Linux lab (see your course syllabus for additional details).
– Be sure to review the program expectations section of the course syllabus.
Initial Testing
Initial tests for the functions are attached to the assignment in Blackboard. A
makefile has been included to run your functions with the sample tests. To use the
makefile, ensure that your program1.cc file and all of the files attached to the
assignment are in the same directory. Your program will be graded using this same
method with additional tests.
The commands to run the sample tests are given below:
make test1
make test2
make test3
make test4
make test5
make test6
You are strongly encouraged to create additional, more rigorous tests.
The six included tests and one new test will be used to grade your program.
Grade Breakdown
Style: 1 point
Documentation: 1 point
Clean compile/link of program1.cc: 1 point
Runs correctly with instructor’s test input 1: 1 point
Runs correctly with instructor’s test input 2: 1 point
Runs correctly with instructor’s test input 3: 1 point
Runs correctly with instructor’s test input 4: 1 point
Runs correctly with instructor’s test input 5: 1 point
Runs correctly with instructor’s test input 6: 1 point
Runs correctly with instructor’s test input 7: 1 point
The penalty for late assignment submissions is 10% per day up to three days after the
assignment due date. No assignment submissions will be accepted more than 3 days after
the due date.

CSCE 240 – Programming Assignment Two

Program Purpose – Implement the functions described below
IsSquare – Function that takes an integer argument and returns whether or not the
argument is a perfect square (is equal to an integer squared).
For example, IsSquare(4) should return true, and IsSquare(5) should return
false.
IsPerfect – Function that takes an integer argument and returns whether or not the
argument is a perfect number. A perfect number is a positive integer that
is equal to the sum of all of its proper divisors.
For example, IsPerfect(6) should return true, because the proper divisors
of 6 are 1, 2, and 3, and 1 + 2 + 3 = 6.
IsPerfect(12) should return false, because the proper divisors of 12 are
1, 2, 3, 4, and 6, and 1 + 2 + 3 + 4 + 6 is not equal to 12.
IsVowel – Function that takes a character and a bool as arguments. If the character
argument is a vowel, the function should return true. If the character
argument is not a vowel, the function should return false.
The bool argument determines whether (true) or not (false) the letter y
should be considered a vowel. The bool parameter should have a default value
of true.
For example, IsVowel(‘y’, false) should return false.
IsVowel(‘y’) should return true.
IsVowel(‘E’) should return true.
IsVowel(‘X’) should return false.
IsVowel(‘u’, false) should return true.
IsConsonant – Function that takes a character and a bool as arguments. If the
character argument is a consonant, the function should return true. If
the character argument is not a consonant, the function should return
false.
The bool argument determines whether (true) or not (false) the letter y
should be considered a consonant. The bool parameter should have a
default value of true.
For example, IsConsonant(‘y’, false) should return false.
IsConsonant(‘y’) should return true.
IsConsonant(‘E’) should return false.
IsConsonant(‘X’) should return true.
IsConsonant(‘g’, false) should return true.
ToDigit – Function that takes a character argument and returns the integer equivalent
of that argument if the argument is ‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’,
‘8’, or ‘9’. If the argument is not a digit character, the function should
return 0.
Range – Function that takes two integer variables as arguments and returns the
distance between the variable’s values. Once the function call is complete,
the variable sent for the first argument should hold the smaller of the two
values, and the variable send for the second argument should hold the larger
of the two value.
For example, if x = 3 and y = 7, Range(x, y) should return 4. And after the
function call is complete, x will still hold 3, and y will still hold 7.
If a = 9 and b = 1, Range(a, b) should return 8. And after the function call
is complete, a should hold 1, and b should hold 9.
DigitInPosition – Function that takes a double and an integer as its two arguments. The
integer argument is the position of the digit in the double to be
returned. The position is relative to the digit in the ones place,
which is position 0. So, position -1 is 1 position to the left of the
ones place, i.e. the tens place. And position 2 is 2 positions to the
right of the ones place, which is the hundredths place.
For example, DigitInPosition(185.34, 0) should return 5 since the 5
is zero positions away from the ones place.
DigitInPosition(185.34, -2) should return 1 since the 1 is two
positions to the left of the ones place.
DigitInPosition(185.34, 1) should return 3 since the 3 is one
position to the right of the ones place.
Additional Specifications
– All function prototypes must be contained in a file named program2functions.h
– All function implementations must be written in a file named program2functions.cc
– You will submit your program2functions.h and program2functions.cc files to the
assignment in Blackboard.
– Programs must compile and run on a computer of the instructor’s choosing in the
Linux lab (see your course syllabus for additional details).
– Be sure to review the program expectations section of the course syllabus.
Initial Testing
Initial tests for the functions are attached to the assignment in Blackboard. A
makefile has been included to run your functions with the sample tests. To use the
makefile, ensure that your program2functions.h and program2functions.cc files and all
of the files attached to the assignment are in the same directory. Your program will be
graded using this same method with modified tests.
The commands to run the sample tests are given below:
make testIsSquare
make testIsPerfect
make testIsVowel
make testIsConsonant
make testToDigit
make testRange
make testDigitInPosition
You are strongly encouraged to create additional, more rigorous tests.
Grade Breakdown
Style: 1 point
Documentation: 1 point
Clean compile/link of program2functions.cc: 1 point
IsSquare passes instructor’s tests: 1 point
IsPerfect passes instructor’s tests: 1 point
IsVowel passes instructor’s tests: 1 point
IsConsonant passes instructor’s tests: 1 point
ToDigit passes instructor’s tests: 1 point
Range passes instructor’s tests: 1 point
IsSquare passes instructor’s tests: 1 point
The penalty for late assignment submissions is 10% per day up to three days after the
assignment due date. No assignment submissions will be accepted more than 3 days after
the due date.

CSCE 240 – Programming Assignment Three

Purpose
Write, test, and use the four functions described below to read a text file
containing a word search grid, display the grid, and find words within the grid.
Functions
Function 1 – ReadWordSearch
Implement the ReadWordSearch function. This function reads a text file
containing the characters into a double-subscripted character array with kSize
rows and kSize columns. kSize is a constant variable set in
word_search_functions.h. This function should return true if the character
array is successfully populated, and false if not. Read over the pre-condition
and post-condition comments in word_search_functions.h for more details.
Function 2 – PrintWordSearch
Implement the PrintWordSearch function. This function takes a doublesubscripted character array with kSize rows and kSize columns as an argument
and outputs the characters at the standard output device (using cout) in a
grid with a space between each column. Read over the pre-condition and postcondition comments in word_search_functions.h for more details.
Function 3 – FindWordRight
Implement the FindWordRight function. This function takes a double-subscripted
character array with kSize rows and kSize columns, a string, and two integer
references as arguments. The function will locate the first occurrence of the
string in the array, written from left to right in a row in the array, and set
the integer reference arguments to the starting position of the string. If the
string appears in a row of the character array, the function returns true. If
the string does not appear in a row in the array, the function returns false.
Read over the pre-condition and post-condition comments in
word_search_functions.h for more details.
Function 4 – FindWordLeft
Implement the FindWordLeft function. This function takes a double-subscripted
character array with kSize rows and kSize columns, a string, and two integer
references as arguments. The function will locate the first occurrence of the
string in the array, written from right to left in a row in the array, and set
the integer reference arguments to the starting position of the string. If the
string appears in a row of the character array, the function returns true. If
the string does not appear in a row in the array, the function returns false.
Read over the pre-condition and post-condition comments in
word_search_functions.h for more details.
Function 5 – FindWordDown
Implement the FindWordDown function. This function takes a double-subscripted
character array with kSize rows and kSize columns, a string, and two integer
references as arguments. The function will locate the first occurrence of the
string in the array, written down in a column in the array, and set the
integer reference arguments to the starting position of the string. If the
string appears in a column of the character array, the function returns true.
If the string does not appear in a column in the array, the function returns
false. Read over the pre-condition and post-condition comments in
word_search_functions.h for more details.
Function 6 – FindWordUp
Implement the FindWordUp function. This function takes a double-subscripted
character array with kSize rows and kSize columns, a string, and two integer
references as arguments. The function will locate the first occurrence of the
string in the array, written up (from bottom to top) in a column in the array,
and set the integer reference arguments to the starting position of the
string. If the string appears in a column of the character array, the function
returns true. If the string does not appear in a column in the array, the
function returns false. Read over the pre-condition and post-condition
comments in word_search_functions.h for more details.
Function 7 – FindWordDiagonal
Implement the FindWordDiagonal function. This function takes a doublesubscripted character array with kSize rows and kSize columns, a string, and
two integer references as arguments. The function will locate the first
occurrence of the string in the array, written diagonally from left to right
in the array, and set the integer reference arguments to the starting position
of the string. If the string appears on a diagonal in the character array, the
function returns true. If the string does not appear on a diagonal in the
array, the function returns false. Read over the pre-condition and postcondition comments in word_search_functions.h for more details.
Example
For the grid below:
e c n e i c t p r o
g r a m r g m a u z
u c l m n o n a e b
i a c w s i g r x t
t v s t l t n y y u
a r e o b x i e i o
r b r h b k t m n w
h a l w l b e a l s
c a w e c n e i c s
p r o g r a m q x z
FindWordRight should find “program” at position 9,0
FindWordLeft should find “science” at position 8,9
FindWordDown should find “guitar” at position 1,0
FindWordUp should find “meeting” at position 9,6
FindWordDiagonal should find “nine” at position 2,4
Specifications
– All output should be directed to the standard output device using cout.
– The prototypes for the FindWordRight, FindWordLeft, FindWordDown, FindWordUp,
and FindWordDiagonal functions are included in word_search_functions.h. Do not
change the contents of the header file, except to modify the constant kSize,
when testing your functions for different size word search grids. You must
implement these functions in word_search_functions.cc, and
word_search_functions.cc must include word_search_functions.h
– You will submit word_search_functions.cc to the assignment in Blackboard.
– Source files must compile and run on a computer of the instructor’s choosing
in the Linux lab (see your course syllabus for additional details).
Testing
A sample text file, grid.txt, containing the example word search grid shown
above, a sample driver to test your functions program3.cc, and a makefile have
been provided. You should ensure that your functions find the words in the
positions provided in the examples. You should search for words that do not
appear in the grid to ensure that the words are not found and your functions do
not crash. You are encouraged to test your functions with additional grids and
search words.
Your functions will be graded using the included program3.cc with modifications
to kSize and the grid.txt input file.
Grade Breakdown
Style: 1 point
Documentation: 1 point
Clean compilation: 1 point
ReadWordSearch passes instructor’s tests: 1 point
PrintWordSearch passes instructor’s tests: 1 point
FindWordRight passes instructor’s tests: 1 point
FindWordLeft passes instructor’s tests: 1 point
FindWordDown passes instructor’s tests: 1 point
FindWordUp passes instructor’s tests: 1 point
FindWordDiagonal passes instructor’s tests: 1 point
The penalty for late program submissions is 10% per day, with no program being
accepted after 3 days.

CSCE 240 – Programming Assignment Four

Purpose – Implement the following two classes
Weight
Create a Weight class that holds the value and units of a weight in private double
and string data members, respectively. The class should allow for the units to be
ounces, pounds, grams, or kilograms. The class will contain a constructor, a
ConvertUnits member function, and accessor and mutator functions for the private
data members. You will also need to overload the <= operator and the stream
insertion operator (<<) for the Weight class.
Read the comments in the supplied weight.h header file for more detailed
requirements.
Also, review initial tests for constructor, mutators, and accessors in
testweight1.cc.
Review initial tests for the ConvertUnits function in testweight2.cc.
Review initial tests for the <= operator in testweight3.cc.
And review initial tests for the stream insertion operator in testweight4.cc.
If you place all of the attached files in the same directory, you can run the
initial tests with the commands
make testweight1
make testweight2
make testweight3
make testweight4
You are strongly encouraged to create more rigorous tests.
WeightRange
Create a WeightRange class that two Weight objects, one to hold the minimum value of
the range and one to hold the maximum value of the range, as private data member.
The class will include two constructors, an InRange member function, a Width member
function, and accessor and mutator functions for the private data members.
Read the comments in the supplied weightrange.h header file for more detailed
requirements.
Also, review initial tests for constructors and accessors in testweightrange1.cc.
Review initial tests for the mutator functions in testweightrange2.cc.
Review initial tests for the InRange function in testweightrange3.cc.
And review initial tests for the Width function in testweightrange4.cc.
If you place all of the attached files in the same directory, you can run the
initial tests with the commands
make testweightrange1
make testweightrange2
make testweightrange3
make testweightrange4
You are strongly encouraged to create more rigorous tests.
Additional Specifications
– Add all code for the definition of the Weight class to the attached weight.h header
file.
– Include all of the necessary code for the Weight class, including the
implementations of the public member functions and the overloaded stream insertion
operator, in the attached weight.cc source file.
– Add all code for the definition of the WeightRange class to the attached
weightrange.h header file.
– Include all of the necessary code for the WeightRange class, including the
implementations of the public member functions, in the attached weightrange.cc
source file.
– You will submit a zip file (only a zip file will be accepted) containing weight.h,
weight.cc, weightrange.h and weightrange.cc to the assignment in Blackboard.
– Source files must compile and run on a computer of the instructor’s choosing in the
Linux lab (see your course syllabus for additional details).
– Your programming assignment will be graded with modified versions of the test files
testweight1.cc, testweight2.cc, testweight3.cc, testweightrange1.cc,
testweightrange2.cc, testweightrange3.cc, and testweightrange4.cc
Grade Breakdown
Style weight.h: 0.25 points
Style weight.cc: 0.25 points
Style weightrange.h: 0.25 points
Style weightrange.cc: 0.25 points
Documentation: 1 point
Clean compilation of weight.cc: 0.5 points
Clean compilation of weightrange.cc: 0.5 points
Weight class passes modified testweight1.cc tests: 1 point
Weight class passes modified testweight2.cc tests: 1 point
Weight class passes modified testweight3.cc tests: 1 point
Weight class passes modified testweight4.cc tests: 0.8 points
WeightRange class passes modified testweightrange1.cc tests: 0.8 points
WeightRange class passes modified testweightrange2.cc tests: 0.8 points
WeightRange class passes modified testweightrange3.cc tests: 0.8 points
WeightRange class passes modified testweightrange4.cc tests: 0.8 points
The penalty for late program submissions is 10% per day, with no program being accepted
after 3 days.

CSCE 240 – Programming Assignment Five

Project Purpose
Implement the two classes described below. Both classes must be added to the
csce240_programming_assignment_5 namespace.
NOTE: The only standard library includes allowed for this project are: iostream and
string. You must properly manage memory using pointers.
SongRecording
private data members:
– a string for the song title
– a pointer to dynamically allocated memory holding the artist name(s) (strings)
– an integer to hold the number of artists (must always be greater than or equal
to 1)
– an integer to hold the length of the track in seconds (must always be nonnegative)
public member functions:
– A constructor that can take the title, primary artist, track length, and number
of artists as its four parameters with default arguments of “untitled”,
“unknown”, 0, and 1, respectively
– A copy constructor
– An overloaded assignment operator
– A destructor
– GetTitle() – Returns the title
– SetTitle(string) – Sets the title to any string that is at least 1 character
long
– GetNumArtists() – Returns the number of artists
– SetNumArtists(int) – Sets the number of artists to any positive integer. Manages
memory for the string pointer data member.
– SetArtist(string, int) – Sets the name of the artist if the string is at least
one character in length, and the integer argument is valid (between 1 and the
number of artists, inclusive). The int parameter should have a default argument
of 1.
– GetArtist(int) – This function should have a default argument of 1. It returns
the name of the specified artist if the integer argument is between 1 and the
number of artists, inclusive. If the integer argument is out of range, the
function should return the string “out of bounds”
– GetTrackLength() – Returns the track length
– SetTrackLength(int) – Sets the value of the track length data member to the
functions argument as long as the argument is non-negative. If the argument is
negative the track length data member should remain unchanged.
Initial testing of the SongRecording class
Include your SongRecording.h and SongRecording.cc files in the same directory as
all of the provided test files and makefile. Type the following commands for
initial tests of the data members and functionality.
make testTitle
make testTrackLength
make testArtist
make testSoundRecordingConstructors1
make testSoundRecordingCopyConstructor
make testSoundRecordingAssignment
You are encouraged to create additional, more rigorous tests!
StreamingTrack – This class must be derived via public inheritance from your
SongRecording class
private data members:
– an integer holding the number of times the track has been streamed
– a pointer to dynamically allocated memory holding the track’s genre(s) (strings)
– an integer hold the number of genres (must be non-negative))
public member functions:
– A constructor that can take the title, primary artist, track length, number of
artists, primary genre, and number of streams as its six parameters with default
arguments of “untitled”, “unknown”, 0, 1, “pop”, and 0 respectively
– A copy constructor
– A constructor that takes a constant reference to a SongRecording, a primary
genre (with a default argument of “pop”), and a number streams (with a default
argument of 0) as its three parameters
– An overloaded assignment operator
– A destructor
– GetStreams() – Returns the number of streams
– SetStreams(string) – Sets the title to any string that is at least 1 character
long
– AddStreams(int) – Increases the number of streams by the argument as long as the
argument is non-negative. If the argument is negative, the data member should
remain unchanged.
– GetNumGenres() – Returns the number of genres
– GetGenre(int) – This function should have a default argument of 1. It returns
the name of the specified genre if the integer argument is between 1 and the
number of genres, inclusive. If the integer argument is out of range, the
function should return the string “out of bounds”
– IsGenre(string) – Returns true if the string argument is one of the
StreamingTrack’s genres, and false otherwise
– AddGenre(string) – Adds the string argument to the StreamingTrack’s genres
(updating the pointer data member and the number of genres data member) if the
argument is not already in the list of genres. If the argument is already one of
the track’s genres, the data members should remain unchanged
– RemoveGenre(string) – Removes the string argument from the StreamingTrack’s
genres (updating the pointer data member and the number of genres data member)
if the argument is in the list of genres. If the argument is not one of the
track’s genres, the data members should remain unchanged
Initial testing of the StreamingTrack class
Include your SongRecording.h, SongRecording.cc, StreamingTrack.h, and
StreamingTrack.cc files in the same directory as all of the provided test files
and makefile. Type the following commands for initial tests of the data members
and functionality..
make testStreams
make testAddGenre
make testRemoveAndAddGenre
make testIsGenre
make testStreamingTrackConstructors1
make testStreamingTrackCopyConstructor
make testStreamingTrackAssignment
make testStreamingTrackBaseToDerivedConstructor
You are encouraged to create additional, more rigorous tests!
Additional Specifications
– The definition of the SongRecording class must be written in a file named
SongRecording.h
– The implementation of the member functions for the SongRecording class must be
written in a file named SongRecording.cc
– The definition of the StreamingTrack class must be written in a file named
StreamingTrack.h
– The implementation of the member functions for the StreamingTrack class must be
written in a file named StreamingTrack.cc
– Both classes must be added to the csce240_programming_assignment_5 namespace.
Classes not added to the csce240_programming_assignment_5 namespace will not be
eligible for correctness points.
– You will submit a zip file containing only SongRecording.h, SongRecording.cc,
StreamingTrack.h, and StreamingTrack.cc to the assignment in Blackboard
– The only standard library headers that may be included in your code are: iostream
and string. Submissions that include other standard library headers will not be
eligible for correctness points.
– Source files must compile and run on a computer of the instructor’s choosing in the
Linux lab (see your course syllabus for additional details).
– Be sure to review the program expectations section of the course syllabus.
Grade Breakdown
Style SongRecording.h: 0.25 points
Style SongRecording.cc: 0.25 points
Style StreamingTrack.h: 0.25 points
Style StreamingTrack.cc: 0.25 points
Documentation: 1 point
Clean compile of SongRecording.cc: 0.5 points
Clean compile of StreamingTrack.cc: 0.5 points
Passes instructor’s modified testTitle: 0.5 points
Passes instructor’s modified testTrackLength: 0.5 points
Passes instructor’s modified testArtist: 0.5 points
Passes instructor’s modified testSoundRecordingConstructors1: 0.5 points
Passes instructor’s modified testSoundRecordingCopyConstructor: 0.5 points
Passes instructor’s modified testSoundRecordingAssignment: 0.5 points
Passes instructor’s modified testStreams: 0.5 points
Passes instructor’s modified testAddGenre: 0.5 points
Passes instructor’s modified testRemoveAndAddGenre: 0.5 points
Passes instructor’s modified testStreamingTrackConstructors1: 0.5 points
Passes instructor’s modified testStreamingTrackCopyConstructor: 0.5 points
Passes instructor’s modified testSoundRecordingAssignment: 0.5 points
Passes instructor’s modified testStreamingTrackAssignment: 0.5 points
Passes instructor’s modified testStreamingTrackBaseToDerivedConstructor: 0.5 points
The penalty for late assignment submissions is 10% per day up to three days after the
assignment due date. No assignment submissions will be accepted more that 3 days after
the due date.