Home » CS107: C++ Programming Certification Exam Answers

CS107: C++ Programming Certification Exam Answers

by IndiaSuccessStories
0 comment

CS107: C++ Programming Exam Quiz Answers

  • Analytical engine
  • ENIAC
  • Altair
  • Von Neumann Architecture
  • C++ class
  • C++ project
  • C++ package
  • C++ program file
banner
  • Line 1: a is a boolean variable, so it cannot accept an integer
  • Line 2: Any calculations must be on the left side of the assignment statement
  • Line 3: Since c is a float, we must assign it the value 4.0
  • Line 4: You must complete the calculations before you can request to output
  • Enter:
  • Enter price:
  • Enter quantity:
  • Enter >>price
  • cin<<age;
  • cin>>age;
  • count<<age;
  • count>>age;
  • 1.0
  • 1.5
  • 2.0
  • 2.5
  • A valid variable name can be up to 40 characters in length.
  • A valid variable name can start with a number and end with a number.
  • A valid variable name may consist of letters, digits, and the underscore (_) character.
  • A valid variable name may contain uppercase letters, which are no different than lowercase letters.
  • 2
  • 1.0
  • 2.0
  • 2.5
  • 22
  • 50
  • 55
  • 56
  • 1, 2, 3, 4, 5, 6, 7
  • 2, 4, 7, 1, 3, 5, 6
  • 6, 7, 5, 1, 2, 3, 4
  • 6, 7, 5, 2, 4, 1, 3
  • 1
  • 5
  • 6
  • 11
  • Alternative execution
  • Chained conditional
  • Nested conditional
  • Unary conditional
  • F5
  • F6
  • F7
  • F8
  • Use the nothrow method
  • Use the noallocate method
  • Check the data before it is entered
  • Use a bad_allocation_fail exception
  • 9, 10
  • 9, 11
  • 10, 11
  • 11, 9
  • swap (2,3); Pass the values as literals
  • swap (&x, &y); Send the address of the variable as an argument
  • &a, &b = swap (x, y); It must be returned to a variable as an address
  • void swap (int &x, int &y); Receive the variables in the parameter as an address
  • phone = “(” + phone. replace (phone. find (‘0’),1,”) “;
  • phone. replace (phone. find (‘-‘), “)”);
  • phone. insert (0,”(“);

phone. replace (phone. find (‘-‘),1,”) “);

  • phone. replace (0,”(“);

phone. replace (phone. find (‘-‘),1,”) “);

  • i and j are equal
  • i is currently larger than j
  • j is currently larger than i
  • The size of j is dynamic and will expand as needed so j will be larger than i
  • When the object has created an error
  • When we want to create a new object
  • When we want to release the memory that the object possesses
  • When we want to capture the memory that the object possesses
  • Explicitly, whenever a new object of the constructor class is created
  • Automatically, whenever a new object of the constructor is destroyed
  • Automatically, whenever a new object of the constructor class is created
  • If it is defined in the class and called when a new object of this class is created
  • void setInfo (string a) {} void (string b) {}
  • void setInfo (int a) {} string setInfo (int a) {}
  • void setInfo (int a, int b) {} void setInfo (int b, int a) {}
  • void setInfo (int a, int b) {} void setInfo (int a, string b){}
  • A reference to a memory location of a variable
  • A pointer to the function that is being executed
  • An object whose member function is being executed
  • A pointer to the object whose member function is being executed
  • Members with one unique value for all the objects of that same class
  • Members with one unique value for all the objects of multiple classes
  • Members with multiple unique values for all the objects of that same class
  • Members with multiple unique values for all the objects of multiple classes
  • friend class Person ();
  • friend Person;
  • class friend Person;
  • friend class Person;
CS107 - C++ Programming
  • Hierarchical inheritance
  • Hybrid inheritance
  • Multilevel inheritance
  • Multiple inheritance
  • The functions appear after the main
  • Main does not call the correct function
  • The functions should have a return value
  • The printLogarithm function should contain an else clause
  • It uses a derived class in a similar manner as the base class, with the use of pointers
  • It takes advantage of the fact that a pointer to a derived class is type-compatible with a pointer to its base class
  • It takes advantage of the fact that a class has only a single function with the same data type pointing to the derived class
  • It makes sure that all pointers in the derived class point to functions within the base class, but not to the operator members
  • 4 5
  • 5 4
  • 10 20
  • 20 10
  • string setName () {return name;}
  • void setName () {name = myname;}
  • string setName(myname) {name = myname;}
  • void setName (string myname) {name = myname;}
  • template<typename T>

class Foo {

public:

Foo ();

void someMethod (typename T x);

private:

typename T x;

};

  • class Foo {

public:

Foo ();

void someMethod (T x);

private:

T x;

};

  • template<typename T>

class Foo {

public:

Foo ();

void someMethod (T x);

private:

T x;

};

  • <typename T>template

class Foo {

public:

Foo ();

void someMethod (T x);

private:

T x;

};

  • #include <iostream>
  • #include <ofstream>
  • #include <ifstream>
  • #include <fstream>
  • throws “Division by zero condition!”;
  • throw “Division by zero condition!”;
  • exception “Division by zero condition!”;
  • catch “Division by zero condition!”;
  • Brian Kernighan
  • Bjarne Stroustrup
  • Dennis Ritchie
  • Ken Thompson
  • When we divide, the result is always a float.
  • When we divide, the result is always an integer.
  • When we divide two integers, the result will always be an integer.
  • When we divide two numbers, the result will be a float, which then gets converted to an integer.
  • cin<<age;
  • cin>>age;
  • cout<<age;
  • cout>>age;
  • A valid variable name can be up to 40 characters in length.
  • A valid variable name can start with a number and end with a number.
  • A valid variable name may consist of letters, digits, and the underscore (_) character.
  • A valid variable name may contain uppercase letters, which are no different than lowercase letters.
  • a contains 3, b contains 3
  • a contains 3, b contains 4
  • a contains 4, b contains 3
  • a contains 4, b contains 4
  • Argument
  • Call
  • Instance
  • Parameter
  • strcmp (s1, s2);
  • strcmp (s1, s3);
  • strcmp (s3, s4);
  • strcmp (s1, “Alpha”);
  • B has goods and S has money
  • B has money and S has goods; B has goods and S has money
  • after, B has goods and S has money; before, B has money and S has goods
  • before, B has money and S has goods; after, B has goods and S has money
  • Constructor with no functions
  • Constructor with no arguments
  • Constructor with one argument
  • Constructor with name argument
  • When there are no parameters
  • When the parameters are undefined
  • When there are no data members defined
  • When the data members have the same name as the parameters passed in
  • Use dot notation
  • Put it in a separate folder
  • Create a different namespace
  • Create a different folder and use dot notation
  • It inherits every member of a base class
  • It only inherits the operator members, not the methods, including constructors and destructors
  • It inherits every member of a base class including the operator members but does not include the constructor and destructor
  • It inherits every member of a base class but it does not inherit its constructor and destructor, operator members, or its friends
  • It requires one argument
  • It may accept multiple parameters
  • The name of the accessor begins with the Set prefix
  • It has a return type consistent with the data being retrieved
  • C
  • COBOL
  • Fortran
  • Java
  • cin<<
  • cin>>
  • cout<<
  • cout>>
  • cin<<
  • cin>>
  • cout<<
  • cout>>
  • boolean
  • char
  • double
  • float
  • 2
  • 6
  • 8
  • 12
  • 0
  • 9
  • 11
  • 16
  • It assigns the value 5 to a and then assigns b+1 to variable a
  • It assigns the value 5 to b and then assigns b+1 to variable b
  • It assigns the value 5 to a and then assigns b+1 to variable b
  • It assigns the value 5 to b and then assigns b+1 to variable a
  • A is 10 and C is 30
  • A is 10 and C is 96
  • A is 15 and C is 30
  • A is 15 and C is 96
  • The size of a variable in computer memory
  • The type of a variable in computer memory
  • The address that locates a variable in computer memory
  • The address that locates the start of a program in computer memory
  • size: 2, length: 2, capacity: 2, max size: 25
  • size: 5, length: 5, capacity: 5, max size: 4611686018427387897
  • size: 25, length: 5, capacity: 25, max size: 25
  • size: 25, length: 25, capacity: 25, max size: 4611686018427387897
  • 70
  • 5900
  • 5952
  • 5970
  • ~Person ();
  • delete Person ();
  • destroy Person ();
  • ~Person (int x, int y);
  • 1
  • 6
  • 12
  • 15
  • It is a group of elements of the same type
  • It is a group of functions of different types
  • It is an expanded concept of a data structure that can hold data
  • It is an expanded concept of a data structure that can hold data and functions
  • 2, 7
  • 7, 8
  • 18, 9
  • 18, 28
  • 2001 A Space Odyssey
  • 2001 A Space Odyssey (1968)
  • My favorite movie is: 2001 A Space Odyssey 1968
  • My favorite movie is: 2001 A Space Odyssey (1968)
  • Class folder
  • Project folder
  • Default folder
  • Application folder
  • candy apples are $10 and pumpkin bread is $5
  • pumpkin bread is 10 and candy apples is 5
  • pumpkin bread is $5 and candy apples are $10
  • pumpkin bread is $10 and candy applies is $5
  • 1
  • 2
  • 2.0
  • 2.5
  • 60000 m
  • 65000 m
  • 20000 s
  • 50000 s
  • When their parameter types are different
  • When the parameters and the parameter types are the same
  • When the parameter types or number of parameters are different
  • When the parameter types are the same but the parameters are different
  • Writing dots here: ………. and then more
  • Writing 5 dots here: …… and then 10 more……….
  • Writing 10 dots here: ………. and then 5 more
  • Writing 10 dots here: ………. and then 10 more……….
  • union employee {

int age;

long salary;

};

  • union Employee {

int age;

long salary;

} employee;

  • union employee {

int age;

long salary;

} Employee;

  • union Employee {

int age;

long salary;

};

  • It is named differently than other data types
  • It can hold more information than other data types
  • It allows you to group multiple like items together into a single set
  • It allows the same portion of memory to be accessed as different data types
  • perimeter does not return a value
  • square does not have access to perimeter
  • rectangle does not have access to perimeter
  • We need to pass a rectangle to perimeter, not a square
  • Line 21
  • Line 22
  • Line 23
  • Line 24
  • Templates
  • Inheritance
  • Abstract functions
  • Function overloading
  • ios: app
  • ios: ate
  • ios: trunc
  • ios: overwrite
  • Line 2
  • Line 3
  • Line 4
  • Line 5
  • New → Add Code
  • New → Source File
  • Project Type → Empty Project
  • Select Configuration → Source File
  • a1= a2;
  • a1 = int(a2);
  • a1 = double(a2);
  • double a1 = a2;
  • It uses OR operation bit by bit between two variables
  • It represents the OR comparison between two variables
  • It uses AND operation bit by bit between two variables
  • It represents the AND comparison between two variables
  • 10, 9, 8, 7, 6, 5, 4, countdown ended!
  • 10, 9, 8, 7, 6, 5, 4, 3 countdown ended!
  • 10, 9, 8, 7, 6, 5, 4, 3, countdown ended!
  • 10, 9, 8, 7, 6, 5, 4, 3, 2 countdown ended!
  • Creates a breakpoint on a specific field
  • Allows you to delete and deactivate stop points
  • Use Java code to define how a variable is displayed
  • Uses the toString () method to determine how to display the variable
  • Branch 1
  • Branch 2
  • Branch 3
  • Branch 4
  • 4, 4
  • 4, 6
  • 6, 24
  • 24, 6
  • Programs don’t run well unless they are inside functions.
  • This allows the programmer to get creative with the code.
  • This makes the program smaller by eliminating repetitive code.
  • This moves the focus of the code to the method instead of the main.
  • Celsius Fahrenheit

-10       23.8

-8         25.8

-6         27.8

-4         29.8

-2         31.8

  • Fahrenheit Celsius

-10            23.8

-8              25.8

-6              27.8

-4              29.8

-2              31.8

  • Celsius Fahrenheit

-10.00   23.80

-8.00   25.80

-6.00   27.80

  • Celsius Fahrenheit 

-10.00     23.80

-8.00      25.80

-6.00      27.80

-4.00      29.80

-2.00     31.80

  • ilovecplusplus.com
  • www.ilovecplusplus.com
  • http://ilovecplusplus.com
  • http://www.ilovecplusplus.com
  • for (int i = 0; i<20; ++i) {}
  • for (int i = 0; i<=20; ++i) {}
  • for (int i = 0; i<values. size (); ++i) {}
  • for (int i = 0; i<=values. size (); ++i) {}
  • Person (name, id)

{

name = name;

id = id;

}

  • Person ()

{

name = “”;

id = “”;

}

  • Person (string name, string id)

{

name = “”;

id = “”;

}

  • Person

{

name = “”;

id = “”;

}

  • It is possible to change the precedence of operators
  • New operators such as **, <> or &/ can be created
  • The overloads of operators && and || lose their short-circuit evaluation
  • &&, ||, and, (comma) maintain their special sequencing properties when overloaded
  • name = this.name;
  • this.name = name;
  • name = this->name;
  • this->name = name;
  • An exception is caught in a try block
  • An exception can be thrown in a try block
  • A try block can be followed by only one catch block
  • It combines the normal case code with the code that handles exceptions

Introduction to C++ Programming

C++ is a powerful, high-performance programming language widely used for system/software development, game development, and in applications requiring real-time processing. Here’s a basic introduction to get you started:

1. Overview of C++

  • Origin: Developed by Bjarne Stroustrup at Bell Labs in the early 1980s, C++ is an extension of the C programming language, adding object-oriented features.
  • Features:
    • Object-Oriented Programming (OOP): Supports classes and objects, inheritance, polymorphism, encapsulation, and abstraction.
    • Low-Level Manipulation: Allows direct manipulation of hardware and memory.
    • Standard Template Library (STL): Provides a set of well-tested classes and functions, like vectors, lists, and algorithms.
    • Performance: Known for high performance and efficiency, making it suitable for applications where resource constraints are critical.

2. Basic Structure of a C++ Program

A simple C++ program typically looks like this:

cppCopy code#include <iostream> // Preprocessor directive to include input-output stream

int main() { // Main function - entry point of the program
    std::cout << "Hello, World!" << std::endl; // Output "Hello, World!" to the console
    return 0; // Return 0 to indicate that the program ended successfully
}

3. Key Components

  • Header Files: Contain declarations of functions and macros. For example, #include <iostream> is used for input and output operations.
  • Namespaces: Avoid name conflicts. The std namespace includes features of the Standard Library.
  • Main Function: The starting point of any C++ program. The int return type signifies the success (0) or failure of the program.

4. Variables and Data Types

C++ supports several data types:

  • Basic Types: int, char, float, double
  • Modifiers: short, long, unsigned, signed
  • Derived Types: Arrays, pointers, references, etc.
  • User-Defined Types: Classes, structs, unions, enumerations.

Example of declaring variables:

cppCopy codeint age = 25;
float salary = 50000.50;
char grade = 'A';

5. Control Structures

  • Conditionals: if, else if, else, switch
  • Loops: for, while, do-while

Example of a loop:

cppCopy codefor(int i = 0; i < 5; i++) {
    std::cout << "i = " << i << std::endl;
}

6. Functions

Functions allow you to encapsulate code into reusable blocks.

cppCopy codeint add(int a, int b) {
    return a + b;
}

int main() {
    int result = add(3, 4); // Calls the function
    std::cout << "Sum: " << result << std::endl;
    return 0;
}

7. Classes and Objects

Classes are blueprints for creating objects. They encapsulate data and functions.

cppCopy codeclass Car {
public:
    // Attributes
    std::string brand;
    int year;

    // Method
    void start() {
        std::cout << "The car is starting." << std::endl;
    }
};

int main() {
    Car myCar; // Create an object of Car
    myCar.brand = "Toyota";
    myCar.year = 2020;
    myCar.start(); // Call the method
    return 0;
}

8. Object-Oriented Concepts

  • Encapsulation: Bundling data and methods into a single unit (class).
  • Inheritance: Creating a new class based on an existing class.
  • Polymorphism: Allowing methods to do different things based on the object they are acting upon.
  • Abstraction: Hiding implementation details and showing only functionality.

9. Standard Template Library (STL)

STL provides various ready-to-use components:

  • Containers: vector, list, map
  • Algorithms: sort, find, copy
  • Iterators: Abstract the way to access elements in containers.

Example of using a vector:

cppCopy code#include <iostream>
#include <vector>

int main() {
    std::vector<int> numbers = {1, 2, 3, 4, 5};
    for(int num : numbers) {
        std::cout << num << std::endl;
    }
    return 0;
}

10. Compiling and Running C++ Code

To compile and run C++ programs, you typically use a compiler like g++:

shCopy codeg++ -o myprogram myprogram.cpp
./myprogram

This command compiles myprogram.cpp into an executable named myprogram.

Overall, C++ is a versatile language known for its performance, flexibility, and wide range of applications. Learning C++ opens up opportunities to work on various software projects and systems programming tasks.

You may also like

Leave a Comment

Indian Success Stories Logo

Indian Success Stories is committed to inspiring the world’s visionary leaders who are driven to make a difference with their ground-breaking concepts, ventures, and viewpoints. Join together with us to match your business with a community that is unstoppable and working to improve everyone’s future.

Edtior's Picks

Latest Articles

Copyright © 2024 Indian Success Stories. All rights reserved.