CSIT 575 – Programming Fundamentals for Computer Science Lab #2E Objectives • To learn to code, compile and run a sequential program • To learn how to obtain a program listing and output printout...

everything is in the pdf file


CSIT 575 – Programming Fundamentals for Computer Science Lab #2E Objectives • To learn to code, compile and run a sequential program • To learn how to obtain a program listing and output printout Assignment Write a C++ program that computes the tax and tip on a restaurant bill. The program will ask the user for their name and the meal cost. The tax should be 9.75% (0.0975) of the meal cost. The program will calculate 15% (0.15) and 20% (0.20) tip rates before tax. Notes: Use named constants for tax rate, 15% tip rate and 20% tip rate Use the data (meal cost) shown below for run #1. You can make up your own data for run #2, but the output format must be the same as sample runs. You must submit two outputs Input Your program should prompt the user to enter a customer’s name and the meal cost. Output Sample Run 1: Enter your first name: Sue Enter the meal cost: 56 ****************************************** Meal Cost 56.00 Tax 5.46 Tip (15%) 8.40 Tip (20%) 11.20 Your total bill is 69.86 after 15% gratuity. or Your total bill is 72.66 after 20% gratuity. Part A: Pseudocode. Include the following Purpose of the program: Input or given data: Processing: Output: CSIT 575 – Programming Fundamentals for Computer Science Lab #3A Objectives To learn to code, compile and run a program containing SELECTION structures Assignment Write an interactive C++·program to have a user input the length of three sides of a triangle. Allow the user to enter the sides in any order. Declare them as integers. 1. Determine if the entered sides form a valid triangle. The triangle may not have negative sides. The sum of any two sides must be greater than the third side to form a triangle. 2. Determine the type of triangle: equilateral triangle—3 sides are equal length isosceles—2 sides are equal length scalene—no sides are equal 3. Use the Pythagorean Theorem, determine if the scalene triangle is a right triangle. (A squared plus B squared equals C squared, where C is the hypotenuse.) Adequately check entered data for validity. Use adequate test data to process all valid data and representative combinations of invalid data. Label output clearly. Be sure your output printout contains user prompts and what was entered by the user in addition to the results of your program processing. As discussed in class, add a simple do..while loop so that you can run all tests in one run. Minimum test data 3 4 5 1 2 0 7 -3 5 6 6 4 7 7 7 2 2 4 You may use additional test data, but you MUST use the previous test data as a minimum. Input--length of three sides of a triangle. Output Length of three sides; type of triangle; whether or not a triangle is a right triangle. Output an appropriate error message for invalid lengths entered for one or more sides or side lengths that cannot form a triangle. Turn in Program listing and program output (Showing all test data which includes valid and invalid data) Include an algorithm written in pseudocode. Extra credit: Declare the sides as doubles. Include isosceles triangles as possible right triangles. CSIT 575 – Programming Fundamentals for Computer Science Lab #4A Objectives To learn to code, compile and run a program containing REPETITION structures Assignment 1. Develop a program to analyze one or more numbers entered by a user. The user may enter one or more numbers for analysis. Input should be limited to numbers from 1 through 1000. 2. Determine if a number is a prime number or not. A prime number is one whose only exact divisors are 1 and the number itself (such as 2, 3, 5, 7, etc.). 3. For non-prime numbers, output a list of all divisors of the number. Format your output so there are between 5 and 10 numbers per line to conserve paper. DO NOT output one number per line. Check your solution with at least 6 numbers: at least 3 prime numbers and at least 3 numbers that are not prime. Check your solution with at least two sets of invalid data. Use good program design, efficient code, and document your code with explanatory comments throughout. Be sure to include adequate error handling in your program and error data when you run the program to demonstrate error handling. Input One or more numbers entered by user, entered one at a time. Program must loop back to the beginning until the user indicates that they are done. Sample Output Input a number between 1 and 1000: -5 That number is not valid. Input another number. Input a number: 17 That is a prime number. Enter a new number: 28 That is not a prime number. Divisors are: 1 2 4 7 14 HOW DOES THIS PROGRAM END?? Extra Credit: Include whether a number is a perfect number. A perfect number is when all divisors add up to the number itself. Example: 6 is a perfect number. 1 + 2 + 3 = 6 Note Adequately check entered data for validity. Use adequate test data to process all valid data and representative data to show how your program handles invalid data. Label all output clearly. Be sure your output file contains user prompts and what was entered by the user in addition to the results of your program processing. Turn in Pseudocode Program listing and program output. Processing Text Files Sequentially File: An area in secondary storage used to hold information. It can be used as input to a program instead of using the keyboard. Can also be used to store output from a program instead of displaying it on the screen. You must know the physical name {file name) of the file on the device. 1. Include the header file fstream in the program. #include 2. Declare the stream (file) variable. ifstream inData; defines an input stream with name inData ofstream outData;· defines an output stream with name outData 3. Open the File. For input file, this means the file name and location must be known. We must check to be sure it is found before processing. For output file, it simply means finding space to put the file on the specified device. inData.open ("prog.dat"); if file is in same place as the program inData.open ("C:\\temp\\prog.dat"); to specify different path. Note the \\ which is required in a path name. outData.open ("prog.dat"); if (!inData) will check for input failure on the open. Be sure to check and stop the program if file not found. 4. Read from the file as with cin. Example: inData >> variablename; Write to file as with cout. Example: outData < variablename;="" all="" the="" iomanip="" functions="" can="" be="" used="" on="" this="" output="" file.="" use="" a="" loop="" to="" continue="" reading="" until="" end="" of="" file="" is="" found:="" while="" (indata)="" this="" will="" return="" false="" on="" end="" of="" file.="" or="" while="" (!infile.eof())="" this="" will="" return="" false="" if="" a="" record="" was="" read,="" true="" if="" the="" end="" of="" file="" mark="" was="" read.="" loop="" will="" continue="" as="" long="" as="" there="" is="" data.="" note="" the="" !="" 5.="" when="" done="" with="" processing,="" close="" the="" file:="" indata.close();="" outdata.close();="" this="" program="" reads="" names="" from="" a="" file="" and="" writes="" them="" to="" another="" file.="" it="" uses="" the="" priming="" read="" approach.="" it="" will="" continue="" until="" end-of-file="" is="" found.="" #include=""> #include #include #include using namespace std; int main() { ifstream infile; ofstream outfile; string name; infile.open ("c:\\temp\\myfile.dat"); if (!infile) //there was an error on open, file not found { cout < "cannot="" open="" file,="" terminating="">< endl;="" exit="" (1);="" }="" outfile.open="" ("c:\\temp\\newfile.dat);="" infile="">> name; //this is called a priming read, only used once while (infile) //or while (!infile.eof()) { outfile <>< endl;="" infile="">> name; }; infile.close(); outfile.close (); return 0; } SAMPLE PROGRAM //This program reads names from a file and writes them to another file. It uses the priming read approach. It will continue until end-of-file is found. #include #include #include #include using namespace std; int main() { ifstream infile; ofstream outfile; string name; infile.open ("c:\\temp\\myfile.dat"); if (!infile) //there was an error on open, file not found { cout < "cannot="" open="" file,="" terminating="">< endl;="" exit="" (1);="" }="" outfile.open="" ("c:\\temp\\newfile.dat);="" infile="">> name; //this is called a priming read, only used once while (infile) //or while (!infile.eof()) { outfile <>< endl;;="" infile="">> name; } infile.close(); outfile.close (); return 0; } CSIT 575 – Programming Fundamentals for Computer Science Lab #5A Objectives To learn to code, compile and run a program using file input and an output file. Assignment Plan and code a program utilizing one file for input and one file for output to solve the following problem: A file contains 7 numbers per line and contains several records. Write a program to input each of the numbers, find the highest number, the lowest
Jun 23, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here