Preview

unit 3

Satisfactory Essays
Open Document
Open Document
313 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
unit 3
Short Answer 5. What two things must you normally specify in a variable declaration?
You must specify the variable type and an identifier. int n; // type - int, identifier - n 6. What value is stored in uninitialized variables?
Some languages assign a default value as 0 to uninitialized variables. In many languages, however, uninitialized variables hold unpredictable values.
Algorithm Workbench
3. Write assignment statements that perform the following operations with the variables a, b, and c.
Adds 2 to a and stores the result in b.
Multiplies b times 4 and stores the result in a
Divides a by 3.14 and stores the result in b
Subtract 8 from b and stores the result in a
4. Assume the variables result, w, x, y , and z are integers, and that w=5, x=4, y=8, and z=2. What value will be stored in result in each of the following statements?
Set result = x + y
Set result = z* 2
Set result = y / x
Set result = y – z
5. Write a pseudocode statement that declares the variable cost so it can hold real number.
6. Write a pseudocode statement that declares the variable total so it can hold real integers. Initialize the variable with the value 0.
7. Write a pseudocode statement that assigns the value of 27 to the variable count.
8. Write a pseudocode statement that assigns the sum of 10 and 14 to the variable total.
9. Write a pseudocode statement that subtracts the variable Down Payment from the variable total and assigns the result to the variable due.
10. Write a pseudocode statement that multiplies the variable subtotal by 0.15 and assigns the result to the variable total fee.

Programming Exercises

6. Sales Tax 8. Tip, Tax, and Total
Design a program that calculates the total amount of meal purchased at a restaurant. The program should ask the user to enter the charge for the food, and then calculate the amount of a 15% tip and 7% sales tax. Display each of these amounts and the total.

You May Also Find These Documents Helpful

  • Satisfactory Essays

    a1 script win213

    • 380 Words
    • 2 Pages

    If the user does not enter a numeric value the program should prompt for a numeric value…

    • 380 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    = z) return true; else return false; } Problem 5 a. Output: 720 b. Output: 0 c. Output: 71 d. Output: 362880 Problem 6 a. Output: “Take Programming I.” b. Output:…

    • 188 Words
    • 1 Page
    Satisfactory Essays
  • Good Essays

    Nt1310 Unit 3 Quiz

    • 6337 Words
    • 26 Pages

    What is the primary purpose of the __P() macro? Choice 1 The __P() macro has no function, and merely obfuscates library function declarat ions. It should be removed from further releases of the C library. Choice 2 The __P() macro provides forward compatibility for C++ compilers, which do not r ecognize Standard C prototypes. Choice 3 Identifiers that begin with two underscores are reserved for C library implement ations. It is impossible to determine the purpose of the macro from the context given. Choice 4 The __P() macro provides backward compatibility for K&R C compilers, which do no t recognize Standard C prototypes. Choice 5 The __P() macro serves primarily to differentiate library functions from applica tion-specific functions. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /*question number 68*/ Which one of the following is NOT a valid identifier? Choice 1 __ident Choice 2 auto [Ans] Choice 3 bigNumber Choice 4 g42277 Choice 5 peaceful_in_space - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /*question number 69*/ /* Read an arbitrarily long string. */ Code: int read_long_string (const char ** const buf) { char * p = NULL; const char * fwd = NULL; size_t len = 0; assert(buf); do { p = realloc(p, len += 256); if (!p) return 0; if (!fwd) fwd = p; else fwd = strchr(p, '\0'); } while (fgets(fwd, 256, stdin)); *buf =…

    • 6337 Words
    • 26 Pages
    Good Essays
  • Satisfactory Essays

    Pt1420 week 2

    • 320 Words
    • 3 Pages

    A customer in a store is purchasing five items. Design a program that asks for the price of each item, and then displays the subtotal of the sale, the amount of sales tax, and the total. Assume the sales tax is 6 percent.…

    • 320 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    UNIT 2

    • 470 Words
    • 3 Pages

    Write a program that will calculate the cost of installing fiber optic cable at a cost of .87 per foot for a company. Your program should display the company name, number of feet installed, and the total cost for the installation.…

    • 470 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Checkpoint 2

    • 294 Words
    • 2 Pages

    The manager of the Supermarket would like to be able to compute the unit price for the product sold here. To do this, the program should input the name and price of an item and its weight in pounds and ounces.…

    • 294 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Nothing

    • 1097 Words
    • 5 Pages

    8) Write (in the same base) the counting numbers just before and just after 1044 five. A) 1043five, 1045 five C) 1043five, 1111 five B) 1042five, 1101 five D) 1043five, 1100 five…

    • 1097 Words
    • 5 Pages
    Good Essays
  • Good Essays

    C++ Midterm

    • 2831 Words
    • 12 Pages

    What is the value inside the "value" variable at the end of the given code snippet?…

    • 2831 Words
    • 12 Pages
    Good Essays
  • Good Essays

    Patient Account Tables

    • 1133 Words
    • 5 Pages

    (b) Add a constraint that Fee should not be less than US$100 and can be null.…

    • 1133 Words
    • 5 Pages
    Good Essays
  • Good Essays

    Friction

    • 771 Words
    • 4 Pages

    Choose the best answer that completes each statement. There is only ONE correct answer for each. Please mark your answers clearly by highlighting your answer. Each multiple choice question is worth one point.…

    • 771 Words
    • 4 Pages
    Good Essays
  • Satisfactory Essays

    Assignment 4

    • 634 Words
    • 3 Pages

    #3. Suppose three values (x, y, and z) are stored in a machine's memory. Describe the sequence of events (loading registers from memory, saving values in memory, and so on) that lead to the computation of x + y + z. How about (2x) + y?…

    • 634 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Programming Homework

    • 823 Words
    • 4 Pages

    B) What do you think the purpose of function? Write appropriate comments into the function to reflect this purpose.…

    • 823 Words
    • 4 Pages
    Satisfactory Essays
  • Good Essays

    6) Write a program to calculate the factorial of a given number. 7) Write a program to calculate sum of squares of cubes of first n natural numbers. 8) Write a program to reverse the given number. 9) Write a program to calculate mn value using do-while loop. 10) Write a program to check whether the given number is a palindrome or not. 11) Write a program to check whether the given number is an Amstrong number or not. 12) Write a program to check whether the given number is a perfect number or not. 13) Write a program to print the following format. * * * * *…

    • 1735 Words
    • 7 Pages
    Good Essays
  • Satisfactory Essays

    1.1 Write a program to calculate the final mark of students and to display the marks in a listbox using sequential files. The input values (icasno, name, ca1, ass, ca2 & exam marks) must be taken from the sequential file…

    • 976 Words
    • 8 Pages
    Satisfactory Essays
  • Satisfactory Essays

    13.a) What is the difference between an algorithm and pseudocode? Also write an Algorithm and pseudocode for solving a quadratic equation. (16)…

    • 2874 Words
    • 12 Pages
    Satisfactory Essays