Itc+lab+14+section+a.docx

  • Uploaded by: Muhammad Fahad
  • 0
  • 0
  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Itc+lab+14+section+a.docx as PDF for free.

More details

  • Words: 828
  • Pages: 4
FAST – NU, CFD Campus National University of Computer and Emerging Sciences

Laboratory Exercise

Introduction to Computing Lab # 13 (CL 101)

Department of Computer Science

FAST – NU, CFD Campus

Page 1

FAST – NU, CFD Campus

Objectives  Enumeration  Filing

Note: Carefully read the following instructions. 1. Make a word document with the convention “ROLLNO_SECTION_LABNO” and put all your C++ source code in it. 2. After every question paste a screenshot of your working code below the source code in the document file. 3. At the end, when you are done with your lab tasks, make your submission on slate.

Problem 1:

1. Define an enumeration type, triangleType, that has the values scalene, isosceles, equilateral, and noTriangle. 2. Write a function, triangleShape that takes as parameters three numbers each of which represents the length of a side of the triangle. The function should return the shape of the triangle. (Note: In a triangle, the sum of the lengths of any two sides is greater than the length of the third side.) 3. Write a program that prompts the user to input the length of the sides of a triangle and outputs the shape of the triangle. Problem 2:

Write a program that can be used to calculate the federal tax. The tax is calculated as follows: For single people, the standard exemption is $4,000; for married people, the standard exemption is $7,000. A person can also put up to 6% of his or her gross income in a pension plan. The tax rates are as follows: If the taxable income is: • Between $0 and $15,000, the tax rate is 15%. • Between $15,001 and $40,000, the tax is $2,250 plus 25% of the taxable income over $15,000. • Over $40,000, the tax is $8,460 plus 35% of the taxable income over $40,000. Prompt the user to enter the following information: • Marital status • If the marital status is ‘‘married,’’ ask for the number of children under the age of 14

FAST – NU, CFD Campus

Page 2

FAST – NU, CFD Campus • Gross salary (If the marital status is ‘‘married’’ and both spouses have income, enter the combined salary.) • Percentage of gross income contributed to a pension fund Your program must consist of at least the following functions: Function getData: This function asks the user to enter the relevant data. Function taxAmount: This function computes and returns the tax owed. To calculate the taxable income, subtract the sum of the standard exemption, the amount contributed to a pension plan, and the personal exemption, which is $1,500 per person. (Note that if a married couple has two children under the age of 14, then the personal exemption is $1,500 * 4 = $6,000.)

Problem 3:

Consider the following incomplete C++ program: #include int main() { ... } a. Write a statement that includes the header files fstream, string, and iomanip in this program. b. Write statements that declare inFile to be an ifstream variable and outFile to be an ofstream variable. c. The program will read data from the file inData.txt and write output to the file outData.txt. Write statements to open both of these files, associate inFile with inData.txt, and associate outFile with outData.txt. d. Suppose that the file inData.txt contains the following data: 10.20 5.35 15.6 Randy Gill 31 18500 3.5 A The numbers in the first line represent the length and width, respectively, of a rectangle. The number in the second line represents the radius of a circle. The third line contains the first name, last name, and the age of a person. The first number in the fourth line is the savings account balance at the beginning of the month, and the second number is the interest rate per year. (Assume that p¼3.1416.) The fifth line contains an uppercase letter between A and Y (inclusive). Write statements so that after the program executes, the contents of the file outData.txt are as shown below. If necessary, declare additional variables. Your statements should be general enough so that if the content of the input file changes and the program is run again (without editing and recompiling), it outputs the appropriate results. FAST – NU, CFD Campus

Page 3

FAST – NU, CFD Campus

Rectangle: Length = 10.20, width = 5.35, area = 54.57, parameter = 31.10 Circle: Radius = 15.60, area = 764.54, circumference = 98.02 Name: Randy Gill, age: 31 Beginning balance = $18500.00, interest rate = 3.50 Balance at the end of the month = $18553.96 The character that comes after A in the ASCII set is B e. Write statements that close the input and output files. f. Write a C++ program that tests the statements in parts a through e.

Problem 3:

Write a program which counts and displays the number of characters (including blanks) in its own source code file.

You are done with your exercise; submit.

FAST – NU, CFD Campus

Page 4

More Documents from "Muhammad Fahad"