Asst 2 Start
/* * Assignment two starting code. */ #include <iostream> #include <sstream> using std::string; const int LIMIT = 79; int main() { // Read the initial left indent and width from standard in. int left, width; std::cin >> left >> width; // Read the rest of the line into a string. string line; std::getline(std::cin,line); // Create a stream from the string to read the numbers it // contains. The object being created is of class std::istringstream, // and it reads using >> just like cin. std::istringstream sections(line); // Use the loop test to read the count of the first item, entering // the loop if the read succeeds. int line_count; while(sections >> line_count) { // Now, declare and read the remaining three items in the // group of four: left_change, width_change, and to_print, // the character to print. (Use any variable names you like.) // Repeat line_count times. Use any loop you like, but here // is one that works: for(int i = 0; i < line_count; ++i) { // Figure out how many spaces to print at the // left. This will be the value of the // variable left, if it is positive, or zero // otherwise. Print that many spaces. Don't // change the value of left; use other // variables for your computation and looping. // Figure out how many copies of to_print you // need to print. Start by making a copy of // width in some other variable. I'll call it // print_width; use what name you like. If // left is negative, reduce print_width by the // number of to_print characters you must omit // because of that. (Can't print left of the // actual monitor.) Then, see if the // remaining run would extend past position // 79. If so, reduce it so you don't go past // the right side of the monitor. Now, if // print_width is positive, print the to_print // character print_width times. // Print an endl // Now it's time to change left and width. Simply // add left_change to left and width_change to width. } } }