1100 C++ Test1

The flashcards below were created by user slc53 on FreezingBlue Flashcards.

  1. 1. C++ is case sensitive. What does this mean?
    1. Capital letters are stored differently than lower case. Eg A is not equal to a
  2. 2. Why do we follow programming standards when writing our programs?
    2. Standards allow maintenance programmers to work faster, therefore changes to programs cost less.

    • 3. All C++ statements end with what character?
    • 3. All C++ statements end with a semicolon.
  3. 4. What is a keyword? How do we identify keywords in our code?
    4. A keyword is a word known by the compiler. Eg int, double, char are keywords.

    • 5. What is a syntax error? Will a program run if there is a syntax error?
    • 5. Syntax errors are caused mostly by typing or spelling mistakes. Programs will not run if there are syntax errors.
  4. 6. What is a logic error? Will a program run if there is a logic error?
    6. Logic errors may happen when statements are in the wrong order are or missing. Programs can run, but do not produce the required results.
  5. 7. We need to enclose the program statements inside________________?
    7. We need to enclose the program statements inside main.
  6. Programming standards:
    • 1) Code brace brackets on lines all by themselves, aligned.
    • 2) indent statements inside brace brackets by at least 2 spaces.
  7. Program execution:
    source -> preprocessor->compiler ->linker ->loader
  8. 1. What is the purpose of the cout statement?
    1. cout statements are used to display output onto the console.

    • 2. What is a preprocessor directive?
    • 2. An example of a preprocessor directive is #include The preprocessor copies code found in the header file iostream into the program.
  9. 3. What does a compiler do?
    3. The compiler translates C++ into machine code.
  10. 4. At what statement does execution begin?
    4. Execution begins at main.

    • 5. Are you allowed to have blank lines in your code?
    • 5. Yes.
  11. 1. What is the format for coding a comment that indicates the rest of the line is a comment?
    1. //rest of the line is a comment
  12. 2. What is the format for coding a comment that uses delimiters to mark the beginning and ending of a comment? When would you use this format?
    2. /* comments appear inbetween these */
  13. 3. Why don’t comments increase the program size when the program runs?
    3. comments are removed by the compiler
  14. 4. Write a comment statement that includes your name.
    4. //donna
  15. 2. How do you continue a C++ statement onto the next line?
    2. Press enter (don’t code semi colon) and indent the statement onto the next line.
  16. 3. Write a cout statement that will print the title ‘Name’ onto the screen.
    3. cout << “name”;
  17. 5. Write a cout statement that will move the cursor to the next line.
    5. cout << endl;
  18. 6. What does endl do?
    6. endl moves the cursor to the beginning of the next line.
  19. 7. What is the purpose of system ("pause"); ?
    7. Prevents the output console from closing. User must close.
  20. 8. Correct the error in the following statements:
    cout << " Hello " , " There " ;
    cout << " Hello " << " There " ;
  21. 8. Correct the error in the following statements:
    cout << " Bye "
    cout << " Now " ;
    • cout << " Bye ";
    • cout << " Now " ;
  22. 8. Correct the error in the following statements:
    cout >> " Hello
                   There " ;
    • cout << " Hello"
    •        << "There " ;
  23. 8. Correct the error in the following statements:
    int Main()
    int main()
  24. 9. Write the statements that will print your name then program major, separated by a blank line.
    cout << "Jeff" << endl << "CNTS";
  25. Describe integer datatype
    • no deciamls e.g. -3, 876
    • size depends on hardware + compiler
    • ours 4 bytes
    • int
  26. Describe character datatype
    • any character on keyboard
    • size is 1byte
    • char
  27. Describe real number datatype.
    • e.g. 1.5 or 5E4
    • 10 dec accuracy
    • size depends on hardware + compiler
    • ours 8 bytes
    • double
  28. Describe string datatype
    • not a built-in datatype, need string header file
    • #include <string>
    • default size is 32 bytes, can be 0 or more than 32
    • string
  29. What datatypes are built in?
    • integers int
    • real numbers double
    • character char
    • bool not covered in COMP1100
  30. 2. If you need to store a number that will be used in arithmetic calculations, which data type(s) would you choose?
    int and double
  31. 3. Which data type would you choose to store your postal code?
    string
  32. 4. How many characters can be stored in a char data type?
    1
  33. 5. Which data type would you choose to store your salary?
    double
  34. 6. Can you store numbers in a string data type?
    yes
  35. 1. What characters can be used when making up variable names?
    letters, numbers and underscore
  36. 2. Give an example of the use of camel caps.
    • camelCaps
    • thisIsCamelCaps
  37. 3. Indicate if the following are valid variable names
    a) char
    b) 4thTest
    c) test#1
    d)overDueAmountThisMonthToDate
    e) test one
    • a) char -no(key word)
    • b) 4thTest-no(can't start with a number)
    • c) test#1 -no(can't use #)
    • d)overDueAmountThisMonthToDate - valid
    • e) test one -no(can't have spaces)
  38. 4. How long can a variable name be?
    Virtually any length
  39. 5. What variable name would you use to store your postal code?
    postalCode
  40. All variables must...
    be declared prior to use, inside main. The are called local variables.
  41. variable Format:
    datatype variable name, variable name, .....variable name;
  42. 1. Write the statement that will declare a variable that will be used to store an employee’s name.
    string empName;
  43. 2. Write the statement(s )that will declare your name and program major.
    string name, major;
  44. 3. Write the statement(s) that will declare variables that will be used to store a product that will be sold in a store and its price.
    • string productName;
    • double price;
  45. 4. Write the statement that will be used to store a 1 byte code that is used to represent a customer’s status.
    char status;
  46. 5. What values are initially found in the variables when declare?
    garbage
  47. 1. Write the statement that will declare a variable to store your age. Initialize it to your age.
    int age=48;
  48. 2. Write the statement that will declare a variable that will store your name. Initialize it to your name.
    string name="Jeff";
  49. 3. Write the statement that will declare 3 integer variables, called test1,test2 and test3. Inialize test1 to 80. Do not initialize test2 and test3. What value will be stored in test2 and test3?
    • int test1=80, test2, test3;
    • test2 and test3 contain garbage
  50. 4. Write the statement that will declare a variable of type char called status. Initialize it to store a 1.
    char status='1';
  51. 4. Write the statement that will declare a constant to store the letter A.
    const char LETTER='A';
  52. How do you temporarily change the datatype to avoid coercion?
    • use static_cast(variable)
    • e.g. static_cast(length)
Author:
slc53
ID:
315872
Card Set:
1100 C++ Test1
Updated:
2016-02-14 20:26:23
Tags:
1100 Test1
Folders:

Description:
1100 C++ Test1
Show Answers: