Bob & Patrick’s Seashell Emporium uses mailing labels for shipping boxes. Write a program to display a mailing label for each box to be shipped. The program output should look similar to:
How many boxes? 2
BOB & PATRICK’S SEASHELL EMPORIUM
UNDER THE SEA, MD 12345
BOX NUMBER 1 OF 2
BOB & PATRICK’S SEASHELL EMPORIUM
UNDER THE SEA, MD 12345
BOX NUMBER 2 OF 2
PROBLEM #2
Write a program that asks the user for starting and ending values and then displays a table of squares and cubes. The program output should look similar to:
Enter starting value: 5
Enter ending value: 12
X X SQUARED X CUBED
5 25 125
6 36 216
…
12 144 1728
PROBLEM #3
Write a program that reads in letter grades for a class of 10 students and displays the number of students who passed (D or better) and the number who failed (E). The program output should look similar to:
Enter a grade: C
Enter a grade: A
…additional inputs not shown here…
6 students passed
4 students failed
#include <iostream>
#include <cmath>
usingnamespace std;
//printTabs function to calculate and output table
void printTabs(int startValO, int rowO)
{
int answer;
for(int i = 1; i <= rowO ; i++)
//start loop to control rows
{
for(int j = 1; j <= 3; j++)
//loop to control columns
{
answer = pow(startValO, j);
//expression to calculate square and cube of starting value/incremented value with column j
cout << answer << '\t';
//out put of integer answer
}
//end of column loop
cout << endl;
}
//end of row loop
}
//End of printTabs
//selTabs to
void selTabs(int startValP, int rowP)
{
//if statement to set increment to 1 if a value of 0 or less us input
printTabs(startValP, rowP);
}
//main function to call table from function printTabs
int main()
{
int startVal, rows;
//user instructions and input
cout << "Enter starting value: ";
cin >> startVal;
cout << "Enter ending value: ";
cin >> rows;
//display headings
cout << "NUMBER" << '\t' << "SQUARE" << '\t' << "CUBE" << endl;
//call and produce table from void function printTabs
selTabs(startVal, rows);
return 0;
}
These 3 questions are totally unrelated to each other. Why did you throw in questions 2 and 3 into this post when you have questions about #1.
What about #1 confuses you?
The "labels" you are to print are the return address labels with a counter. It is extremely straight forward. What do you not understand? If you say "I don't know" or "all of it", I'll know I'm talking to my own kids, and will lose all patience.
(Please check)!
Problem 3 doesn't even compile. Neither program does what it is supposed to do. Why haven't you tried running the program and seeing if it works before bringing it to us? And don't ask us what's wrong, tell us what's wrong and tell us what you don't understand.
To read in the grades for 10 students, you either need a loop to read the grade for each student (good) or explicit code to read grades for 10 students (bad).
#include <iostream>
#include <cmath>
usingnamespace std;
//printTabs function to calculate and output table
void printTabs(int startValO, int rowO, int incrementO)
{
int answer;
for(int i = 1; i <= rowO ; i++)
//start loop to control rows
{
for(int j = 1; j <= 3; j++)
//loop to control columns
{
answer = pow(startValO, j);
//expression to calculate square and cube of starting value/incremented value with column j
cout << answer << '\t';
//out put of integer answer
}//End of row loop
startValO += incrementO;
// to increment the initial value
cout << endl;
}//End of row loop
}//End of printTabs
//selTabs to
void selTabs(int startValP, int rowP, int incrementP)
{
//if statement to set increment to 1 if a value of 0 or less us input
if(incrementP < 1)
incrementP = 1;
printTabs(startValP, rowP, incrementP);
}
//main function to call table from function printTabs
int main()
{
int startVal, rows, increment;
//user instructions and input
cout << "Enter starting value: ";
cin >> startVal;
cout << "Enter the number of values to be displayed: ";
cin >> rows;
cout << "Enter the increment between the values: ";
cin >> increment;
//display headings
cout << "NUMBER" << '\t' << "SQUARE" << '\t' << "CUBE" << endl;
//call and produce table from void function printTabs
selTabs(startVal, rows, increment);
return 0;
}
For problem 3 I dunno how to loop so it gets all 10 sudents
Well it now produces correct output. 7/10. Why selTabs() function - increment check can go in printTabs()? Why loop j = 1? pow(startValo, 1) is just startVal0? So print the number outside of the j loop and start j at 2. Also the displayed numbers don't align with the headings.
problem 3.
As you say you're proficient with python, then you must know/understand loops. If you're unsure re the C++ syntax for loops, look at previous examples to see use.
That is one way of doing it which works - just, but it's not very good code. If statements can use || for logical or and && for logical and. In this case a for loop is also a better choice than a while loop.
There is also no checking for invalid grade entered or to deal with upper-case/lower-case input. The original problem used upper-case letters.
I'm pretty sure is was an int in a previous post, too, that was subsequently deleted. It was the post that asked why specific lines had red syntax error squiggles.
But when posts get deleted, following posts lose their context.
Instead of hard coding that two in the line above, make a variable to hold it and ask the user the question, then let them type in the response.
Once you have it, you will run a loop that many times - take a peek at the slides about for loops - there is probably an example in there really similar to what you need.
Then as the loop runs, you will print this - once inside the loop
on this last line, you will fill in with the variable controlling your loop where the 1 is, and with the variable you originally read the user input into where the 2 is
cout << "BOX NUMBER 1 OF 2" << endl;
The code you posted has absolutely nothing to do with the steps YOU delineated two posts earlier.
You have an int variable named i that is never used, and a string variable named numberBoxes that is, as I said, a string, so can't be used for counting.
You ask for customer address, but you are printing return mailing labels, so the customer address is meaningless.
Why don't you show code for the following?
Basically
cout << "How many boxes? 2" << endl;
Instead of hard coding that two in the line above, make a variable to hold it and ask the user the question, then let them type in the response.
Once you have it, you will run a loop that many times - take a peek at the slides about for loops - there is probably an example in there really similar to what you need.
Then as the loop runs, you will print this - once inside the loop
on this last line, you will fill in with the variable controlling your loop where the 1 is, and with the variable you originally read the user input into where the 2 is
cout << "BOX NUMBER 1 OF 2" << endl;