Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ The only library functions you are allowed to use are: emath, climits, cstdl

ID: 3604449 • Letter: C

Question

C++

The only library functions you are allowed to use are: emath, climits, cstdlib: all String: empty, length, conatenation, indexing/at, relational operators iostream: , getline (with cin, cout, cerr) fsream: all of above, open, close, eof, fail 2. (15%) Suppose your program has the following declarations to represent information about a course. enum Department {CSCI,MATH, ENGLISH; Department dept; in number // between 100 and 499 (inclusive) name ; string // Ez.‘‘ Writing,, (possibly empty) Per policy, freshman, sophomore, junior, and senior courses are numbered in the 100s, 200s, 300s, and 400s, respectively. Write C++ conditions (Boolean expressions) corresponding to each of the following sets. Your answers should be as compact as possible, and cover all cases (including empty strings). (a) Math çourses that are at the junior or senior levels (c) Courses whose names end with the letter z.

Explanation / Answer

From the enum if the dept is equal to MATH then it is maths department course.

junior and senior levels are indicated by course number between 300 and 500.

So the boolean expression for math courses that are at the junior or senior levels is :

dept == MATH && ( number >= 300 && number <= 499 )

/* if dept is maths and number belongs to senior or junior level */

next courses ending with the letter z.

as name of the course is a string we can use the string method end to find the iterator to the end of the string.

Here's how is it used.

name.end() - 1 returns the iterator pointing to the last charecter in the string. It must be eqaul to z.

So the boolean conditions is :

*( name.end() - 1 ) == 'z' /* checks it he last char in the string is z or not */

there is another way to do the same. We have a size() method in string that retuns the number of charecters in the string. we can also this

name[ name.size() - 1 ] == 'z' // similar to the above boolean condition

/* hope this helps */

/* if any queries please comment */

/* thank you */

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote