was hoping someone with more experience could look over and tell me if these answers look alright.
in red is what i got

-- srand:
a. Should be called before each call to rand.
b. Should be used instead of rand to generate truly random numbers.
c. Is unnecessary in C++.
d. Can use the time function’s return value as an optimal seed value.

--Enumeration constants:
a. Must have unique integer values.
b. Can be assigned other values once they have been defined.
c. Must have unique identifiers.
d. Are declared using the keyword const.

--Which of the following is not a valid enumeration statement?
a. Enum person { me, you, them };.
b. Enum person { me = 1, you = 2, them = 3 };.
c. Enum person { me = 0, you = 0, them = 0 };.
d. Enum person { me, you, me };.

( for this one kinda guest, my logic was that they cannot be all the same or game would be infinite as will always be same)


thanks,

lgonz

Dani AI

Generated

Quick clarification for (and a nod to : compiling and testing is a good habit). Short answers: for the srand question pick d; for the enumeration-constants question pick c; the invalid enum is the one that repeats the same identifier (d). Below are concise reasons, tiny examples you can compile, and a couple of cautions.

srand: the function seeds the C-style generator used by rand() and is normally called once at program startup — not before every rand() call. Using time() (e.g. std::time(nullptr)) as a seed is common, but it gives only coarse entropy (seconds) and is not suitable for security. Example usage:

#include <cstdlib>
#include <ctime>

int main() {
    std::srand(static_cast<unsigned>(std::time(nullptr))); // seed once
    int r = std::rand();
}

(en.cppreference.com)

Prefer the C++11 <random> facilities for better quality and clearer intent: pick an engine (e.g. std::mt19937) and seed it once with std::random_device (or a std::seed_seq for stronger seeding). Example:

#include <random>

std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<int> dist(0, 100);
int x = dist(gen);

(en.cppreference.com)

Enumerations: enumerator names (identifiers) must be unique in the same scope, but the underlying integer values may repeat. They are declared with enum (not const). So the statement that enumerators “must have unique identifiers” is correct; “must have unique integer values” is false. The invalid enum in the multiple-choice is the one that repeats the same name (me twice), which is a compile error:

enum Person { Me, You, Them };       // OK
enum Dup   { A = 0, B = 0, C = 1 };  // duplicate values OK
// enum Bad { X, Y, X };            // invalid: duplicate identifier X

(en.cppreference.com)

These points should let the multiple-choice answers stand on their own and explain the “why” behind them.

You're just asking someone to do your homework. You can find the answer to the first question by running a google search for srand. Since this is for a C++ class, I can only assume you are able to compile C++ code, which would let you verify the answers for #2 and #3.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.