C++ test3

Home > Preview

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


  1. 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.
  2. 3. What does a compiler do?
    3. The compiler translates C++ into machine code.
  3. 4. At what statement does execution begin?
    4. Execution begins at main.
  4. 3. Why don’t comments increase the program size when the program runs?
    3. comments are removed by the compiler
  5. 3. Indicate if the following are valid variable names a) char
    no: is a key word
  6. 3. Indicate if the following are valid variable names b) 4thTest
    no: can't start with a number
  7. 3. Indicate if the following are valid variable names c) test#1
    no: can't use special characters
  8. 3. Indicate if the following are valid variable names d)overDueAmountThisMonthToDate
    yes
  9. 3. Indicate if the following are valid variable namese) test one
    no: can not use spaces
  10. 5. What values are initially found in the variables when declare?
    garbage
  11. How many bytes is an int?
    4
  12. how many bytes is a double?
    8
  13. how many bytes is a string?
    32
  14. how many bytes is a char?
    1
  15. 1. Write the statement that will declare a constant called PI initializing it to 3.414
    const double PI=3.14;
  16. char code[25]={‘a’,’b’,’c’}; What value is stored in the last element?
    a space
  17. Given int numbers[6]={4,3}; a) Draw the array.
    [4,3,0,0,0,0]
  18. Given int numbers[6]={4,3}; b) What is the length of the array?
    2
  19. Given int numbers[6]={4,3}; c) What is the size of the array?
    6
  20. Given int numbers[6]={4,3}; d) What is the value of numbers[1]?
    3
  21. Given int numbers[6]={4,3}; e) What is wrong with the statement cin>>numbers[6];
    outside array
  22. Given int numbers[6]={4,3}; f) Write the statement that will add 2 to the first element in the array.
    numbers[0]+=2
  23. int grades[8];

    what is grade[0]=
    garbage
  24. int numb[3];
    numb[0]=5;

    what is numb[1]=
    garbage
  25. int numb[3]={5};

    what is numb[1]=
    0
  26. how to end a loop with Ctrl+z?
    • if (cin.eof())
    • break;

    • how do you clear the input buffer for a string entry after an int or double entry?
    • cin.ignore(80,'n');
  27. 2. show the values in the following arrays: a) int numb[5];
    garbage, size=5
  28. 2. show the values in the following arrays: b) int value[5]={40,30,30};
    {40,30,30,0,0} size=5
  29. 2. show the values in the following arrays:c) int numb[]={1,3,4,5};
    {1,3,4,5} size =4(auto)
  30. 2. show the values in the following arrays: d) string names[5]={ "J. Doe", "P. Smith" };
    { "J. Doe", "P. Smith",,, }
  31. 2. show the values in the following arrays:e) char code[3]={ '1'};
    { '1',' ',' '}
  32. 2. show the values in the following arrays:f) double width[]={1.9,3.9,4.9,5.0};
    {1.9,3.9,4.9,5.0}
  33. what happens with for(;;)
    infinite loop
  34. for (int ctr = 0; ctr<5; ctr++) //if declare ctr in for loop it can’t be used after loop T/F
    T
  35. for (int ctr = 0; ctr<5; ctr++)
    cout << ctr << endl;
    cout << ctr << endl; //is okay? T/F
    F
  36. for (int ctr = 0; ctr<5; ctr++)
    cout << ctr << endl; //is okay? T/F
    T, as long as ctr is not used outside the loop
  37. cout<<"Enter a number between 1 and 100 code:";
    • cin>>numb;
    • while (cin.fail()||numb<0||numb>1000)
    • {
    • cin.clear();
    • cin.ignore(80,'n');
    • cout<<"re-enter";
    • cin >> num
    • }
    • cin.clear(80,'n') //in cin for text later
  38. Validate a product code.
    • string productCode;
    • cout << "enter a product code";
    • while (productCode.length() == 0)
    • {
    • cout << "You did not enter a product code." << endl;
    • cout << "Enter a product code: ";
    • getline(cin, productCode);
    • }
  39. how to open a file.
    • ofstream fout("products.dat");
    • if (!fout.is_open())
    • {
    • cout << "The file products.dat could not open - need to fix" << endl;
    • system("pause");
    • exit(666);
    • }

    • how to send file to console
    • system("type products.dat");
  40. beginning of file:
    • #include <iostream>
    • #include <string>
    • #include <iomanip>
    • #include <fstream>
    • using namespace std
  41. code for decimals:
    fout << fixed << setprecision(2); // or cout
  42. cout << "Enter a product code (or ctrl Z to end): ";
    • getline(cin, productCode);
    • while (!cin.eof())
    • {...}

Card Set Information

Author:
slc53
ID:
319345
Filename:
C++ test3
Updated:
2016-04-25 02:44:42
Tags:
test3
Folders:

Description:
C++ test3
Show Answers:

Home > Flashcards > Print Preview