Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following program, write the code in C++, please do it well, make sure you show all steps and how you did it. Please make

The following program, write the code in C++, please do it well, make sure you show all steps and how you did it. Please make the code such that I can copy paste it. Also please show the output as well, as sometimes the code is given but there is not a correct output, so show a screenshot of your output and that it matches everything asked in the question.

The following is the introduction to the assignment that is required for various tasks but you only have to do the last 2 right now. I have already done the other tasks, so I will send the files and for this you have to build on the code and add on the files for the codes for tasks. You have to do trapezoid.cpp/h and checkerboard3x3.cpp/h but i will send the cpp and header files for all the other tasks just so you have an idea of how it should look like, and you should add the functions to the main.cpp for those 2. You have to add the functions for these codes for it to run and compile. The codes for task f and g should be added to it. Please follow all these directions, and make sure all files that I have sent the code of are present and list the names of the files you have and the code for it

This is the intro to the assignment:

For this assignment, you will have to create a Makefile to build your project. It should create a single executable named main.

The main function should call all the functions that accomplish the tasks. Those functions may not be written in main.cpp but rather you should create at least one additional .cpp/.h file(s).

Write a function for each of the tasks. The functions should accept parameters for the assorted dimensions and should return a std::string with a string representing the output. Recall that you can embed a newline in a string to move to the next line.

The main function should call each task function one or more times and print out the results to show that everything works.

For example, for task A you might write a routine with a prototype std::string box(int width, int height).

You might test it from main as follows:

image text in transcribed

Note: Remember that your program should not ask for any keyboard input. When run it should clearly show that all tasks are implemented and work.

IMPORTANT: NO USER/KEYBOARD INPUT, REMEMBER THAT WHEN MAKING THE CODE

These are the instructions for task a, b,c, d, and e that i have done and with the code beneath:

image text in transcribedimage text in transcribed

image text in transcribedimage text in transcribedimage text in transcribed

Following all directions above, this is the five tasks that I have completed and I will send the code I did for these tasks:

This is my code, with the name of the files listed, the code of the files and the output, (look at all this carefully, this is the platform you will make the codes for task d for)

Makefile:

CXX = g++

CXXFLAGS = -std=c++11

OBJS = main.o box.o

all: main

main: $(OBJS)

$(CXX) $(CXXFLAGS) -o main $(OBJS)

main.o: main.cpp box.h

$(CXX) $(CXXFLAGS) -c main.cpp

box.o: box.cpp box.h

$(CXX) $(CXXFLAGS) -c box.cpp

clean:

rm -f $(OBJS) main

Main.cpp:

#include

#include "box.h"

#include "lower.h"

#include "upper.h"

#include "checkerboard.h"

#include "cross.h"

int main() {

int width, height;

// Task A: box

std::cout

std::string result = box(5, 6);

std::cout

std::cout

std::cout

//Task B: checkerboard

std::cout

result = checkerboard(8, 4);

std::cout

std::cout

//Task C: cross

std::cout

result = cross(9);

std::cout

std::cout

// Task D: lower triangle

std::cout

result = lower(4);

std::cout

std::cout

std::cout

// Task E: upper triangle

std::cout

result = upper(4);

std::cout

std::cout

std::cout

//Task F: trapezoid function goes here

//Task G: checkerboard 3x3 function goes here

return 0;

}

box.cpp:

#include "box.h"

//Task A for box.cpp this is the cpp file, you have to make a cpp file for Task F, "trapezoid.cpp and a cpp file for Task G, "checkerboard3x3.cpp"

std::string box(int width, int height) {

std::string shape = "";

for (int i = 0; i

for (int j = 0; j

shape += "*";

}

shape += " ";

}

return shape;

}

box.h:

#ifndef BOX_H

#define BOX_H

#include

std::string box(int width, int height);

#endif // BOX_H

checkerboard.cpp:

#include "checkerboard.h"

//Task B for checkerboard.cpp this is the cpp file

std::string checkerboard(int width, int height) {

std::string shape = "";

std::string firstChar = "";

std::string secondChar = "";

// loop to print the characters

for (int row = 0; row

firstChar = " ";

secondChar = "*";

if (row % 2 == 0) {

firstChar = '*';

secondChar = ' ';

}

for (int col = 0; col

if (col % 2 == 0) {

shape += firstChar;

}

else {

shape += secondChar;

}

}

shape += " ";

}

return shape;

}

checkerboard.h:

#ifndef CHECKERBOARD_H

#define CHECKERBOARD_H

#include

std::string checkerboard(int width, int height);

#endif // CHECKERBOARD

cross.cpp:

#include "cross.h"

//Task C for cross.cpp this is the cpp file

std::string cross(int size) {

std::string shape = "";

//std::string line = "";

int counter = 0;

// Loop to print the pattern

for (int i = 0; i

for (int i = 0; i

if ((i == counter) || (i == (size -1 )- counter)) {

shape += "*";

}

else {

shape += " ";

}

}

shape += " ";

counter += 1;

}

return shape;

}

cross.h:

#ifndef CORSS_H

#define CORSS_H

#include

std::string cross(int size);

#endif // CORSS

(I just sent the header and cpp files for first 3 tasks, the other 2 tasks I have also done a cpp and header file for but it is not necessary here so you can just use these 3 cpp and header files to get an understanding of how to develop the code for your 2 tasks.

So as i have cross.h, cross.cpp, etc you have to make files for trapezoid.cpp, trapezoid.h and same for checkerboard3x3.cpp, checkerboard3x3..h, please do it well, and make sure to add the functions for main.cpp

(as said in the comment for main.cpp I made the cpp file for the first five tasks which is the cpp file for these tasks, and then you have to make the task f and g cpp files as i wrote in comments. This is in addition to the functions you add in main.cpp as well as the header files you should make for the functions)

These are the two tasks you have to do for task f and g in which the above directions apply:

image text in transcribed

image text in transcribed

Please follow all directions well, make all the files and functions as asked and make sure when ran together it runs, list the name of the files and the code following it beneath when you send it. There should be the makefile that I already have, the updated main.cpp with added functions, and the cpp files for the other tasks and any additional header files needed. Follow all directions well, please.

Overall: the box.cpp, checkerboard.cpp, cross.cpp etc I made for first 3 tasks is not necessary for you, just to give you an idea what you do, but the files you should be sending are the updated main.cpp with added functions, the trapezoid.cpp and trapezoid.h and checkerboard3x3.cpp and checkerboard3x3.h Please send the screenshot of the output as well, so i know it works and make sure the code compiles.

MAKE SURE NO USER INPUT, IT SHOULD BE HARD CODED AS WELL, AND THERE SHOULD BE THE CPP AND HEADER FILES, AS WELL AS THE FUNCTIONS ADDED TO MAIN. FOLLOW ALL DIRECTIONS WELL, AND READ EVERYTHING, URGENT.

// more code up here std::string result; result = box (3,5); std: : cout "box (3,5): "; std: :cout result std: : cout " ------------- "; // seperator // more tests to show that box works fully could be added // more code down here Write a program that asks the user to input width and and prints a solid rectangular box of the requested size using asterisks. Also, print a line between user input and the printed shape (to separate input from output). Example: Input width: 7 Input height: 4 Shape: Write a program checkerboard.cpp that asks the user to input width and and prints a rectangular checkerboard of the requested size using asterisks and spaces (alternating). Example: Input width: 11 Input height: 6 Shape: Write a program that asks the user to input the shape , and prints a diagonal cross of that dimension. Example: Inputsize:8 Task D. Lower triangle Write a program lower.cpp that prints the bottom-left half of a square, given the side length . Example: Input side length: 6 Shape: Task E. Upper triangle Nrite a program upper.cpp that prints the top-right half of a square, given the side length . xample: O Input side length: 5 Shape: Task F. Upside-down trapezoid Write a program trapezoid.cpp that prints an upside-down trapezoid of given width and height . However, if the input height is impossibly large for the given width, then the program should report, Impossible shape! Example 1: Input width: 12 Input height: 5 Shape: Example 2: Input width: 12 Input height: 7 Impossible shape! Hint: You can start with the number of spaces=0;stars=width; On each line, print that number of spaces followed by that number of stars. After that, the number of spaces gets incremented by 1 , while the number of stars gets decremented by 2 : spaces+=1;stars=2; Task G. Checkerboard (33) Write a program checkerboard 33.cpp that asks the user to input width and height and prints a checkerboard of 3-by-3 squares. (It should work even if the input dimensions are not a multiple of three.) Example 1: Inputwidth:16Inputheight:11 Example 2: Input width: 27 Input height: 27

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

Database And Expert Systems Applications Dexa 2021 Workshops Biokdd Iwcfs Mlkgraphs Al Cares Protime Alsys 2021 Virtual Event September 27 30 2021 Proceedings

Authors: Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil ,Bernhard Moser ,Atif Mashkoor ,Johannes Sametinger ,Anna Fensel ,Jorge Martinez-Gil ,Lukas Fischer

1st Edition

3030871002, 978-3030871000

More Books

Students also viewed these Databases questions