Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab2: Vector The purpose of this lab is for you to familiar with C++ vector and using Makefile. Makefile is used so you can compile

image text in transcribed

image text in transcribed

image text in transcribedimage text in transcribedimage text in transcribed

Lab2: Vector The purpose of this lab is for you to familiar with C++ vector and using Makefile. Makefile is used so you can compile multiple source codes files and link them to a program executable. I have also provided a sample Makefile for you to use for all labs within this class. If you want to know more about Makefile, here is more information from the website: I have provided an example of this lab written in array, you need to modify the program so it is implemented in vector and use Makefile per the requirement below: 1. Create a new folder and place all lab2 files in this folder. 2. In lab1, you wrote the print_me_first() function. You need to change the print_me_first to function, and save the file to print_me_first.cpp file. 3. You need to use Makefile for this lab since we will have separate .cpp files. Please use the sample Makefile I have created for this lab. Please refer to my lecture as I will go over Makefile. In the lab folder, you should have the following files in the folder: a) Makefile b) print_me_first.cpp c) vectorstructTax.cpp For example, your folder should be similar as below: CS116 2020FA Lab Lab2_Vector W C++ C++ C++ Makefile array. structKey. cpp lab2- vector 2020FA. docx print_me_ first.cpp print_me_ first.h vectorstruc tTax.cpp 4. Create a new cpp vectorstructTax.cpp, make sure it is in the same folder where the Makefile is located. 5. Use the sample array_structKey.cpp file, and reimplement it but uses vector instead. The new cpp filename should be vectorstructTax.cpp since I used it in the Makefile. If you change to a different name, you need to modify Makefile to reflect the new name change. 6. In the vectorstructTax.cpp file, you also need to #include "print_me_first.h" (please refer to my lecture) O In the sample array_structKey.cpp, it uses array taxpayer taxpayerList[3]; Create a new file vectorstructTax.cpp o In this lab, you need to use vector taxpayerList; o Rewrite the array_structKey.cpp program but using vector instead. Your need to call print_me_first() function at the beginning of your program. Your new vectorstructTax.cpp should have the following output: o Program written by: Course info: CS-116 Lab2 Vector Date: Sun Sep 13 15:35:44 2020 Please enter the annual income and tax rate for tax payers: Enter this year's income for tax payer 1: 100000 Enter the tax rate % for tax payer # 1: 12.5 Enter this year's income for tax payer 2: 150000 Enter the tax rate % for tax payer # 2: 17.85 Enter this year's income for tax payer 3: 250000 Enter the tax rate % for tax payer # 3: 22 Taxes due for this year: Tax Payer # 1 income: $ 100000.00 Tax Payer # 1 tax rate: 12.50% Tax Payer # 1 taxes: $ 12500.00 Tax Payer # 2 income: $ 150000.00 Tax Payer # 2 tax rate: 17.85% Tax Payer # 2 taxes: $ 26775.00 Tax Payer # 3 income: $ 250000.00 Tax Payer # 3 tax rate: 22.00% Tax Payer # 3 taxes: $ 55000.00 G+ array_structKey.cpp > ... 1 // This program demonstrates how to use an array of strucures 2 #include 3 #include 4 #include "print_me_first.h" 5 6 using namespace std; 7 8 struct taxpayer 9 { 10 float taxRate; 11 float income; 12 float taxes; 13 }; 14 15 int main() 16 { 17 taxpayer taxpayerList[3]; 18 19 print_me_first("Ron Sha", "CS-116 array example"); 20 cout > taxpayerList[count]. income; 29 30 cout > taxpayerList[count].taxRate; 32 33 cout ... 1 \/PrintMeFirst.cpp 2 #include 3 #include #include 5 #include "print_me_first.h" 6 using namespace std; 7 /** 9 * @Purpose this function print out the person who wrote the program, 10 * and date/time the program run. 11 * @parm name the author of the program 12 * @parm courseInfo the name of the course 13 * @return 14 * @file PrintMeFirst.cpp 15 * @author -Haiyan 16 **/ 17 18 void print_me_first(string name, string courseInfo) 19 { 20 cout ... 1 2 #ifndef PRINT_ME_FIRST_H 3 #define PRINT_ME_FIRST_H #include 5 6 using namespace std; 7 /** 9 * Define the header information for PrintMeFirst 10 * forward declaration tells the compiler that the function 11 * PrintMeFirst() is defined else where so just go use it, and 12 * it will be resolved during the linking time. 13 * @file PrintMeFirst.h 14 * @author Ron Sha 15 **/ 16 17 18 void print_me_first(string name, string courseInfo); 19 20 #endif 21 Lab2: Vector The purpose of this lab is for you to familiar with C++ vector and using Makefile. Makefile is used so you can compile multiple source codes files and link them to a program executable. I have also provided a sample Makefile for you to use for all labs within this class. If you want to know more about Makefile, here is more information from the website: I have provided an example of this lab written in array, you need to modify the program so it is implemented in vector and use Makefile per the requirement below: 1. Create a new folder and place all lab2 files in this folder. 2. In lab1, you wrote the print_me_first() function. You need to change the print_me_first to function, and save the file to print_me_first.cpp file. 3. You need to use Makefile for this lab since we will have separate .cpp files. Please use the sample Makefile I have created for this lab. Please refer to my lecture as I will go over Makefile. In the lab folder, you should have the following files in the folder: a) Makefile b) print_me_first.cpp c) vectorstructTax.cpp For example, your folder should be similar as below: CS116 2020FA Lab Lab2_Vector W C++ C++ C++ Makefile array. structKey. cpp lab2- vector 2020FA. docx print_me_ first.cpp print_me_ first.h vectorstruc tTax.cpp 4. Create a new cpp vectorstructTax.cpp, make sure it is in the same folder where the Makefile is located. 5. Use the sample array_structKey.cpp file, and reimplement it but uses vector instead. The new cpp filename should be vectorstructTax.cpp since I used it in the Makefile. If you change to a different name, you need to modify Makefile to reflect the new name change. 6. In the vectorstructTax.cpp file, you also need to #include "print_me_first.h" (please refer to my lecture) O In the sample array_structKey.cpp, it uses array taxpayer taxpayerList[3]; Create a new file vectorstructTax.cpp o In this lab, you need to use vector taxpayerList; o Rewrite the array_structKey.cpp program but using vector instead. Your need to call print_me_first() function at the beginning of your program. Your new vectorstructTax.cpp should have the following output: o Program written by: Course info: CS-116 Lab2 Vector Date: Sun Sep 13 15:35:44 2020 Please enter the annual income and tax rate for tax payers: Enter this year's income for tax payer 1: 100000 Enter the tax rate % for tax payer # 1: 12.5 Enter this year's income for tax payer 2: 150000 Enter the tax rate % for tax payer # 2: 17.85 Enter this year's income for tax payer 3: 250000 Enter the tax rate % for tax payer # 3: 22 Taxes due for this year: Tax Payer # 1 income: $ 100000.00 Tax Payer # 1 tax rate: 12.50% Tax Payer # 1 taxes: $ 12500.00 Tax Payer # 2 income: $ 150000.00 Tax Payer # 2 tax rate: 17.85% Tax Payer # 2 taxes: $ 26775.00 Tax Payer # 3 income: $ 250000.00 Tax Payer # 3 tax rate: 22.00% Tax Payer # 3 taxes: $ 55000.00 G+ array_structKey.cpp > ... 1 // This program demonstrates how to use an array of strucures 2 #include 3 #include 4 #include "print_me_first.h" 5 6 using namespace std; 7 8 struct taxpayer 9 { 10 float taxRate; 11 float income; 12 float taxes; 13 }; 14 15 int main() 16 { 17 taxpayer taxpayerList[3]; 18 19 print_me_first("Ron Sha", "CS-116 array example"); 20 cout > taxpayerList[count]. income; 29 30 cout > taxpayerList[count].taxRate; 32 33 cout ... 1 \/PrintMeFirst.cpp 2 #include 3 #include #include 5 #include "print_me_first.h" 6 using namespace std; 7 /** 9 * @Purpose this function print out the person who wrote the program, 10 * and date/time the program run. 11 * @parm name the author of the program 12 * @parm courseInfo the name of the course 13 * @return 14 * @file PrintMeFirst.cpp 15 * @author -Haiyan 16 **/ 17 18 void print_me_first(string name, string courseInfo) 19 { 20 cout ... 1 2 #ifndef PRINT_ME_FIRST_H 3 #define PRINT_ME_FIRST_H #include 5 6 using namespace std; 7 /** 9 * Define the header information for PrintMeFirst 10 * forward declaration tells the compiler that the function 11 * PrintMeFirst() is defined else where so just go use it, and 12 * it will be resolved during the linking time. 13 * @file PrintMeFirst.h 14 * @author Ron Sha 15 **/ 16 17 18 void print_me_first(string name, string courseInfo); 19 20 #endif 21

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

More Books

Students also viewed these Databases questions