Question

CSCI 111 Assignment 4 Aim: To write some programs using loops, arrays and library functions. Procedure: Part A: Consider an a

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I am storing Box State as Boolean and Printing Closed Box Numbers and Total Closed Boxes
Result:

PS C:\Users Documents C++> g++ . ass4A.cpp PS C:\Users Documents\C++> . \a.exe Closed Box Numbers: 1 4 9 16 25 36 49 64 81 10

Files:

This PC > Documents > C++ Name Type Size E a.exe ass4A.cpp Date modified 10/17/2019 12:18. 10/17/2019 12:18 ... Application C
Code (Text Code also included in End):

2 3 #include <iostream> using namespace std; int main() // Initializing Variables const int boxes = 150; bool states[boxes];
Code:

#include <iostream>
using namespace std;
int main()
{
    // Initializing Variables
    const int boxes = 150;
    bool states[boxes];

    // Closing All Boxes
    for(int i = 0; i < boxes; i++){
       states[i] = false;
   }

    // Changing States of Alternate Boxes
   for(int i = 2; i <= boxes; i++){
       for(int j = i; j <= boxes; j += i){
        // Reversing State
        states[j - 1] = !states[j - 1];
    }
}

// Print Closed Box Numbers
int totalClosed = 0;
cout << "Closed Box Numbers:\n";
for(int i = 0; i < boxes; i++){
    if (!states[i]){
        cout << (i + 1) << " ";
        totalClosed += 1;
    }

}
cout << "Total Closed Boxes:" << totalClosed;
return 0;
}

Add a comment
Know the answer?
Add Answer to:
CSCI 111 Assignment 4 Aim: To write some programs using loops, arrays and library functions. Procedure:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Assignment 6: Recursion Learning Outcomes • Learn how to craft solutions using recursion instead of loops....

    Assignment 6: Recursion Learning Outcomes • Learn how to craft solutions using recursion instead of loops. Instructions This assignment will be different than previous assignments (and most assignments which come after it). In this assignment, you will be crafting four solutions to four different problems. This assignment will also have special requirements regarding how you may code. You are not allowed to use assignment statements. This includes using preincement, postincrement, predecrement, and postdecrement. You are allowed to use assignment to...

  • CMPS 12B Introduction to Data Structures Programming Assignment 2 In this project, you will write...

    can i get some help with this program CMPS 12B Introduction to Data Structures Programming Assignment 2 In this project, you will write a Java program that uses recursion to find all solutions to the n-Queens problem, for 1 Sns 15. (Students who took CMPS 12A from me worked on an iterative, non-recursive approach to this same problem. You can see it at https://classes.soe.ucsc.edu/cmps012a/Spring l8/pa5.pdf.) Begin by reading the Wikipcdia article on the Eight Queens puzzle at: http://en.wikipedia.org/wiki/Eight queens_puzzle In...

  • Note: None of these functions should use cout. It is OK to use cout while debugging...

    Note: None of these functions should use cout. It is OK to use cout while debugging to check how your function is working, but your final submission should not contain cout in any function but main. Head ==== Name the source file for this section head.cpp. Write a function named "head" which takes an array of integers as an argument, and returns the first element in the array. Write a function named main which outputs the result of testing your...

  • I would like some assistance correcting an issue I am having with this assignment. Once a...

    I would like some assistance correcting an issue I am having with this assignment. Once a finite state automaton (FSA) is designed, its transition diagram can be translated in a straightforward manner into program code. However, this translation process is considerably tedious if the FSA is large and troublesome if the design is modified. The reason is that the transition information and mechanism are combined in the translation. To do it differently, we can design a general data structure such...

  • Objective: Write a program that implements the Game of Life cellular automata system invented by John...

    Objective: Write a program that implements the Game of Life cellular automata system invented by John Conway. 1. Create two game grids of size at least 50x50. These grid cells can be either Boolean or integer. In the following, I’ll refer to these as gridOne and gridTwo. 2. Set all cells in both grids to false. 3. Start by initializing gridOne. Allow the user to specify two different ways of initializing the grid: 1) by specifying a pattern file to...

  • 1.2 Recruitment is one of the crucial functions of HRM. Based on the information provided below,...

    1.2 Recruitment is one of the crucial functions of HRM. Based on the information provided below, how would you describe THE COMPANY’s approach to recruitment, before and after the implementation of the Brand Ambassador Program? How did the use of social media lead to the revision of the whole approach regarding recruitment? How ‘THE COMPANY’ Developed a Brand Ambassador Program At ‘THE COMPANY’ we usually categorize Employment Brand at ‘THE COMPANY’ into four big ‘buckets’: candidate experience, brand ambassador programs,...

  • Solve it for java Question Remember: You will need to read this assignment many times to...

    Solve it for java Question Remember: You will need to read this assignment many times to understand all the details of the you need to write. program Goal: The purp0se of this assignment is to write a Java program that models an elevator, where the elevator itself is a stack of people on the elevator and people wait in queues on each floor to get on the elevator. Scenario: A hospital in a block of old buildings has a nearly-antique...

  • Name_year_test.c #include "Name_year.h" #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <string.h> void print_name_year(const Name_year * ny) {   ...

    Name_year_test.c #include "Name_year.h" #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <string.h> void print_name_year(const Name_year * ny) {    printf("%s,%d\n", ny->name, ny->year); } int main() {    char * ny_format = "%s,%d\n"; #if PHASE >= 1    puts("Phase 1 tests");    // Make sure we can create an object and get the data back.    // We're creating the name as a local array so that we can    // make sure that create_name_year() does not merely make    // a copy of...

  • 2) What were some of the key challenges they encountered? How did they overcome them? 3)...

    2) What were some of the key challenges they encountered? How did they overcome them? 3) What were some of the key takeaways they learned to use in the future? When I assumed the leadership of Heinz’s Asia/Pacific business, in 1993, the company’s revenues from that part of the world were hardly a blip—and I’d never visited most of the countries in the region. I made my first trip there soon after I took the job, and it really opened...

  • I need help with my very last assignment of this term PLEASE!!, and here are the instructions: After reading Chapter T...

    I need help with my very last assignment of this term PLEASE!!, and here are the instructions: After reading Chapter Two, “Keys to Successful IT Governance,” from Roger Kroft and Guy Scalzi’s book entitled, IT Governance in Hospitals and Health Systems, please refer to the following assignment instructions below. This chapter consists of interviews with executives identifying mistakes that are made when governing healthcare information technology (IT). The chapter is broken down into subheadings listing areas of importance to understand...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT