C++ LAB

Mutahr36
CPP_Instruction_SP2021_LAB3_Accessibility.docx

COSC 1436 – LAB3

Contents TILLE 1 TIME TO COMPLETE 1 HOW TO DO PART 2 1 Step1: 1 Step2: 1 Step3: 1 Step4: 1 Step5: 2 LAB3 - PART1 REQUIREMENT 2 Question 1: ( needs 3 answers) 2 Question 2: (need 5 answers) 2 Question 3: 3 Question 4: 4 LAB3 - PART2 REQUIREMENT 4 HOW TO TURN IN THE LAB 5 HOW TO GRADE THE LAB 5

TILLE: Read Input from keyboard – Sale In Day Report

TIME TO COMPLETE: two weeks

HOW TO DO PART 2

Remember to do the lab with the following:

*If you need help about the C++ syntax to write the code, read the instruction in the folder “Skills Required”

*From now and on yourLastName will be changed to your last name

*Your program should change Smith to your last name

*Change James Smith to your full name

*write the file name as the first comment line at the top of program

*After running your program, take the picture of the output window as below from your program with your name on and paste the picture at the bottom of the document having pseudo-code to turn in

Step1:

Read the requirement; write in English the pseudo-code in a word document by listing the step by step what you suppose to do in main() and then save it with the name as Lab3_pseudoCode_yourLastName

(store pseudo-code and output pictures of both part 1 and part 2)

Step2:

Start Virtual Studio C++, create the project write the project name

For Part 2: SP2021_LAB3PART2_yourLastName

Add .cpp file

For Part 2: SP2021_SaleInDay_yourLastName.cpp

After adding the cpp file, you have an empty window coming up, type the following template of a C++ program in:

//File name should be written here as comment line

#include <iostream>

using namespace std;

int main()

{

//add the code here below this line

…..

system(“pause”); //This will pause the output to read

return 0;

}

Step3:

Then follow the step by step in the pseudo-code, type the C++ code in after the line “//add the code here below this line”

Step4:

Compile and run the program

Step5:

Debug if there are any errors until compile successfully

LAB3 - PART1 REQUIREMENT

Use a word document to write the answers of the following questions:

Question 1: ( needs 3 answers)

We have the following lines of code:

#include <iostream>

using namespace std;

int main()

{

float fvar1, fvar2;

int ivar;

char cvar;

cout << "Enter two decimal numbers, one integer number and one character : " << endl;

cin >> fvar1 >> fvar2 >> cvar >> ivar;

cout << fvar1 << “ - “ << fvar2 << “ – “ << cvar << “ – “ << ivar << endl;

system("pause");

return 0;

}

What are three output you get after you run the above lines of code in three times and each time, provide one of the following input:

Input of case a: 55.3 78.62.78 S 4

Input in case b: 86 32.4P 92.6

Input in case c: 12 .45 32 A

Question 2: (need 5 answers)

We have the following lines of code:

#include <iostream>

using namespace std;

int main()

{

int ivar;

double dvar;

char cvar;

cout << "Enter one integer number, one character, one decimal number : " << endl;

cin >> ivar >> cvar >> dvar;

cin.ignore(80, '\n');

//case a

cout << ivar << " - " << cvar << " - " << dvar << endl << endl;

cout << "Enter one decimal number, one integer number, one character : " << endl;

cin >> dvar >> ivar >> cvar;

cin.ignore(80, '\n');

//case b:

cout << dvar << " - " << ivar << " - " << cvar << endl << endl;

cout << "Enter one integer number, one character, one decimal number : " << endl;

cin >> ivar; cin.get(cvar); cin >> dvar;

cin.ignore(80, '\n');

//case c:

cout << ivar << " - " << cvar << " - " << dvar << endl << endl;

cout << "Enter one carácter, one integer number, one decimal number : " << endl;

cin >> cvar >> ivar >> dvar;

cin.ignore(80, '\n');

//case d:

cout << cvar << " - " << ivar << " - " << dvar << endl << endl;

cout << "Enter a character, one integer, one decimal number : " << endl;

cin.get(cvar); cin >> ivar >> dvar;

cin.ignore(80, '\n');

//case e:

cout << cvar << " - " << ivar << " - " << dvar << endl << endl;

system("pause");

return 0;

}

If we type in the same “23 5.6 2021” at each time the program asks for input

What are the five output you have from the program?

Question 3:

we have the following lines of code:

#include <iostream>

#include <string>

using namespace std;

int main()

{

char cvar;

string svar1, svar2;

cout << “Enter a string: “;

cin >> svar1;

cin.get(cvar);

getline(cin, svar2);

cout << svar1 << " - " << cvar << " - " << svar2 << endl << endl;

cin.ignore(80, '\n');

cout << “Enter a string: “;

cin >> svar1;

cin >> cvar;

getline(cin, svar2);

cout << svar1 << " - " << cvar << " - " << svar2 << endl << endl;

system("pause");

return 0;

}

Use the same input “Hi there! This is a test.” to enter a string for two times asking input.

What are two output from the above program?

Question 4:

During each summer, John and Jessica grow vegetables in their backyard and buy seeds and fertilizer in various bag sizes. When buying a particular fertilizer, they want to know the price of the fertilizer per pound and the cost of fertilizing per square foot.

The following program prompts the users to enter the size of the fertilizer bag, in pounds, the cost of the bag and the area, in square feet, that can be covered by the bag. The program should output the desired results, the price per pound and the cost of each square foot fertilize.

However, the program contains logical errors because it has lines of the code are not in correct order.

You should find and move lines of the code back to correct order to fix the logical errors so that the program works properly.

using namespace std;

#include <iostream>

int main()

{

cout << fixed << showpoint << setprecision(2);

cout << "The cost of the fertilizer per pound is: $"

<< bagCost / bagSize << endl;

cout << "The cost of the fertilizer per square foot is: $"

<< bagCost / bagAreaCovered << endl;

cout << "Enter the amount of fertilizer, in pounds, in the bag: ";

cin >> bagSize;

system("pause");

#include <iomanip>

cout << "Enter the cost of the " << bagSize

<< " pound fertilizer bag: ";

cin >> bagCost;

double bagCost;

int bagSize;

cout << "Enter the area, in square feet, that you want to fertilizer? ";

cin >> bagAreaCovered;

double bagAreaCovered;

return 0;

}

LAB3 - PART2 REQUIREMENT

Provide the C++ application that can help the users to have the summary of the sale during the week.

The program will ask and read the information from keyboard:

*the name (String) of the person who is using the program,

*Current date in the format “mm/dd/yyyy” (string)

*Unit price (float) and number of units sold (int) in the day of 5 products of the company

Then the program will calculate the sold amount of each product type and total money sold of 6 product types

The output should as below with the information will be aligned to the right

File name: SP2021_SaleInDay_Martinez.cpp

Name of the person reporting: MARY LANE

Current day: 01/19/2021

-------------------------------------------------------------------------------------------------------------------------------------------------

PRODUCT1 PRODUCT2 PRODUCT3 PRODUCT4 PRODUCT5

-------------------------------------------------------------------------------------------------------------------------------------------------

Unit Price: 8.29 10.59 11.29 12.59 14.29

Number of Units sold 70 72 75 80 75

------------------------------------------------------------------------------------------------------------------------------------------------

Money: 580.30 762.48 846.75 1007.20 1071.75

TOTAL SOLD: 4268.48

The following picture is the output window from the program:

Picture shows the output of part 2 lab3

HOW TO TURN IN THE LAB

You turn in the following files:

LAB3PART1_ yourLastName.docx (part1)

Pseudo-code and output pictures of the part 2

FA2021_WeekExerciseReport_yourLastName.cpp

FA2021_LAB3PART2_yourLastName.exe

IF YOU GET ANY PROBLEM TO SUBMIT FILE .class, YOU CAN SUBMIT ALL PROJECT INTO ONE FILE .zip or .rar

HOW TO GRADE THE LAB

ITEMS TO GRADE

MAX SCORE

TURN IN THE LAB ON TIME

3

Part1: question 1

3

Part1: question 2

4

Part1: question 3

2

Part1: question 4

2

PART2

Pseudo-code – output pictures

1

Define variables to hold values from input

2

Calculate the sum of time and sum of distance

2

Calculate the average of time and average of distance

2

Output as required format with alignment and distance in decimal with 2 digits

4

Compile success qualify the requirements

3

Comments – File name as the first comment line

2

Total Scores

30

Instructor: Liem Le – COSC1436 1