Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Identify invalid identifier(s) and explain the reasons why they are invalid. 40Hours year cost_in_$ number1 include int box-44 Student-name DVD_ROM 2morrow Determine the appropriate data

  1. Identify invalid identifier(s) and explain the reasons why they are invalid.
  1. 40Hours
  2. year
  3. cost_in_$
  4. number1
  5. include
  6. int
  7. box-44
  8. Student-name
  9. DVD_ROM
  10. 2morrow

  1. Determine the appropriate data type for the following data:

(a) The average of four marks.

(b) The number of days in a month.

(c) The length of the Penang Bridge.

  1. Code the variable definitions for each of the following:

(a) A character variable named option.

(b) An integer variable, sum, initialized to 0.

(c) A floating-point variable, product, initialized to 1.

  1. Write single C++ statement to perform each of the following tasks:

(a) Declare num1, num2, and num3 as integer type variables.

(b) Declare tempA, tempB, and tempC as double precision type variables. Initialize tempA to value 28.9.

  1. Write the output for each of the following segments of code.

(a) int x = 7;

int y = 3;

cout << x/y << " and " << x%y;

(b) double b = 5;

cout << b/2 << (int) b%2;

  1. Briefly explain and correct the error(s) in each of the code segments below.

(a) int a = 5;

int double = 2*a;

int triple = 3*a;

cout << "Doubling 5 gives " << double << " and tripling gives " << triple;

(b) int x, y;

cin << x << y;

cout << "x = " << x << " y = " << y;

  1. Suppose x, y, and z are int variables and x = 2, y = 5, and z = 6. What is the output of each of the following statements?

  1. cout<<"x = "<

    if (character == 'A')

    cout << "Hello!";

    else if (character == 'B')

    cout << "Happy Birthday!";

    else if (character == 'C')

    cout << "Thank you!";

    else

    cout << "Welcome!";

    10. Assume that the tuition fee for year 1 and year 4 is RM1200.45 and RM2267.30 respectively without considering the Code. The fee for year 2 and year 3 is determined by code as shown in the table below:

    Year

    Code

    Fee (RM)

    1

    1200.45

    2 or 3

    A

    1789.00

    B

    2005.50

    Others

    2200.90

    4

    2267.30

    Write a nested if statement to assign the fee value based on the conditions above.

    11. Declare an 11-element array of characters called arr_alpha and store in it the alphabets from A to J.

    12. (a) Declare a character array called name, which contains the string Programming.

    1. Display the 5th character of name based on 12 (a) on screen.

    (c) Replace the 1st character of name based on 12 (a) with the letter p.

    13. (a) Declare an array, called number, to store 8 integer numbers.

    (b) Assign the value 5 to the last element of the array number based on Q5 (a).

    (c) Write C++ statements display all integers in the array number and then display its total and average.

    14. (a) Write a declaration for COST, which is an array that can be used to store 10 item cost

    prices to two decimal places. Initialize COST to 0.00.

    1. Write a C++ program segment to read (from the keyboard) the 10 item cost prices into the array COST.

    1. Write a statement to change the fourth items price to 8.00.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transact SQL Cookbook Help For Database Programmers

Authors: Ales Spetic, Jonathan Gennick

1st Edition

1565927567, 978-1565927568

More Books

Students also viewed these Databases questions

Question

Working with other project stakeholders for support.

Answered: 1 week ago

Question

Knowledge of project management (PMI) teachings

Answered: 1 week ago