Module 2

Cards (31)

  • Relational operators can be used on struct variables. True or False

    False
  • What is the file open mode that delete all previous content in the file?

    ios::trunc
  • The components of a struct are called the _____ of the struct.
    members
  • A struct is a homogenous data structure with all components of the same type. True or False?
    False
  • A struct is typically a _____ data structure.

    heterogenous
  • Statement to close an ifstream inFile of filename "studentData.dat".

    outFile.close();
  • In C++, a struct is a reserved word. True or False

    True
  • A struct variable can be passed as a parameter _______.
    • Only be reference
    • Only by value
    • Either by value or by reference
    • Only by const
    either by value or by reference
  • Statement to close an ofstream outFile of filename "studentData.dat".

    outFile.close();
  • In structs, you access a component by using the struct name together with the relative position of the component. True or False?

    False
  • You can use an assignment statement to copy the contents of one struct into another struct of the same type. True or False?
    True
  • A struct is a definition and a declaration. True or False?
    False
  • A function can return a value of type struct. True or False?
    True
  • Memory is allocated when you defined a struct. True or False?
    False
  • A struct can be passed as a parameter to a function by value or by reference. True or False
    True
  • A member of a struct can be another struct. True or False

    True
  • Typically, in a program, a struct is defined before the definitions of all functions. True or False?

    True
  • Both arrays and structs are example of structured data types. True or False

    True
  • Step number 3 for general file I/O.
    Associate the file stream variables with the input/output sources.
  • Data in a struct variable must be read one member at a time. True or False
    True
  • An array can be a member of a struct. True or False

    True
  • The components of a struct are accessed by name. True or False

    True
  • You can use the assignment statement on structs. True or False

    True
  • The components of the struct are called the variable of the struct. True or False
    False
  • If all members of a struct are of the same type, you can also use an array as data structure to manipulate the data. True or False
    True
  • Which of the following is an allowed aggregate operation on a struct?
    1. Input/output
    2. Comparison
    3. Arithmetic
    4. Assignment
    Assignment
  • The syntax for accessing a struct member is structVariableName_________.
    .memberName
  • void QZ2Simulation(){
    int num[10];
    ofstream outFile;
    outFile.open("QZ2.txt");
    stand(time(0));
    for (int ctr=0; ctr<10; ctr++) //first loop
    num[ctr] = (rand()%100*2);
    for(int ctr=0, value=1; ctr<10; ctr++, value++)
    num[9-ctr] = num[ctr]/2;
    for(int ctr=0, value=1; ctr<10; ctr++, value++)
    outFile<<num[ctr]<<endl;
    }
    What will be the output (content of text file) of the program snippet presented if the following random numbers where generate in the first loop (36, 14, 92, 146, 148, 76, 116, 78, 58, 178)?
    9 3 23 36 37 74 73 46 7 18
  • Consider the following statements:
    struct rectangleData {
    double length,
    width,
    area,
    perimeter;
    };
    rectangleData bigRect;

    Which of the following statements is valid in C++?
    if (bigRect.length == width)
    if (bigRect != smallRect)
    if (bigRect == smallRect)
    if (bigRect.length == smallRect.width)
    if(bigRect.length == smallRect.width)
  • Consider the following struct definition: struct rectangleData {
    double length,
    width,
    area,
    perimeter; };
    Which of the following variable declaration is correct?
    a.struct rectangleData();
    b. rectangle rectangleData;
    c. rectangleData myRectangle;
    d. rectangleData rectangle = new rectangleData();
    rectangleData myrectangle;
  • Consider the following statements:
    struct rectangleData
    {
    double length;
    double width;
    double area;
    double perimeter;
    };
    rectangleData bigRect;
    rectangleData smallRect;

    Which of the following statements is legal in C++?
    if (bigRect.length == width)

    if (bigRect != smallRect)

    if (bigRect == smallRect)

    if (bigRect.length == smallRect.width)


    if (bigRect.length == smallRect.width)