Question

In: Computer Science

The main purpose of this lab is to reinforce the lectures on code style and documentation....

The main purpose of this lab is to reinforce the lectures on code style and documentation.

Make as many improvements to the code style as you can including white space, variable names, etc. (NOTE: do this manually – no automated formatting tools allowed). Comment the file completely.

#include <iostream>

#include <cmath>using namespace std;

const int A_CONSTANT = 3;

void functionA(int a[], int aNumber);

void functionB(int a[], int anotherNumber);

void functionC(const int anArray[], int aNumber);

void functionD(int& sum);

int functionE(double number); void functionF(int n);

int main( ){

int production[A_CONSTANT];

cout << "This program displays a graph showing\n" << "production for each factory in the company.\n";

functionA(production, A_CONSTANT);

functionB(production, A_CONSTANT);

functionC(production, A_CONSTANT);

return 0;}

void functionA(int a[], int aNumber){

for (int someNumber = 1;someNumber <= aNumber; someNumber++)

{ cout << endl << "Enter production data for plant number " << someNumber << endl; functionD(a[someNumber - 1]);}}

void functionD(int& sum){

cout << "Enter number of units produced by each department.\n" << "Append a negative number to the end of the list.\n";

sum = 0; int next;

cin >> next;

while (next >= 0) {

sum = sum + next;

cin >> next; }

cout << "Total = " << sum << endl;

  

}

void functionB(int a[], int anotherNumber){

for (int index = 0; index < anotherNumber; index++)

a[index] = functionE(a[index]/1000.0);

  

}

int functionE(double number) {

return static_cast<int>(floor(number + 0.5));

  

}

void functionC(const int anArray[], int aNumber){

cout << "\nUnits produced in thousands of units:\n";

for (int someNumber = 1; someNumber <= aNumber; someNumber++) {

cout << "Factory #" << someNumber << " ";

functionF(anArray[someNumber - 1]);

cout << endl;

}

}

void functionF(int n) {

for (int count = 1; count <= n; count++) cout << "*";

  

}

Solutions

Expert Solution

PascalCase: In pascal case starting letter of each word should be capitalized. It is easy for reading.

Example: LongFunctionName;

camelCase: It is same as PascalCase except the first letter should not be capitalized.

example: longFunctionName:

* We used camelCase for function names and varibale names

It is common in c++ to use camelCase for functions and varible names.

In our code everything looks good except the indentation. So i adjusted it.

#include <iostream>

#include <cmath>

using namespace std;

const int A_CONSTANT = 3;

void functionA(int a[], int aNumber);

void functionB(int a[], int anotherNumber);

void functionC(const int anArray[], int aNumber);

void functionD(int& sum);

int functionE(double number);

void functionF(int n);

int main( )
{
    int production[A_CONSTANT];
    cout << "This program displays a graph showing\n" << "production for each factory in the company.\n";
    functionA(production, A_CONSTANT);
    functionB(production, A_CONSTANT);
    functionC(production, A_CONSTANT);
    return 0;
  
}

void functionA(int a[], int aNumber){
    for (int someNumber = 1;someNumber <= aNumber; someNumber++)
    {
        cout << endl << "Enter production data for plant number " << someNumber << endl;
        functionD(a[someNumber - 1]);
      
    }
  
}

void functionD(int& sum){
    cout << "Enter number of units produced by each department.\n" << "Append a negative number to the end of the list.\n";
    sum = 0; int next;
    cin >> next;
    while (next >= 0)
    {
        sum = sum + next;
        cin >> next;
      
    }
    cout << "Total = " << sum << endl;
  
}

void functionB(int a[], int anotherNumber){
    for (int index = 0; index < anotherNumber; index++)
    a[index] = functionE(a[index]/1000.0);
  
}

int functionE(double number) {
    return static_cast<int>(floor(number + 0.5));
  
}

void functionC(const int anArray[], int aNumber){
    cout << "\nUnits produced in thousands of units:\n";
    for (int someNumber = 1; someNumber <= aNumber; someNumber++)
    {
        cout << "Factory #" << someNumber << " ";
        functionF(anArray[someNumber - 1]);
        cout << endl;
      
    }

}

void functionF(int n)
{
    for (int count = 1; count <= n; count++)
    cout << "*";
}

/* Hope you like my answer. If you have any doubts comment this answer*/


Related Solutions

**********************************java********************************************************** Purpose: The purpose for this project is to reinforce the knowledge from Chapter 9 of...
**********************************java********************************************************** Purpose: The purpose for this project is to reinforce the knowledge from Chapter 9 of the textbook. The students will learn how to write a user defined class. Project Objectives: Apply UML design on user defined class Write overloaded constructors of a class Write mutators (i.e. get methods) and accessors (i.e. set methods) of a class Write overloaded methods Write main method to test the user defined class Class Diagram: Student must implement the Temperature class according to the...
Purpose: This lab will give you experience modifying an existing ADT. Lab Main Task 1: Modify...
Purpose: This lab will give you experience modifying an existing ADT. Lab Main Task 1: Modify the ListInterface Java interface source code given below. Change the name of ListInterface to ComparableListInterface, and have ComparableListInterface inherit from the built-in Java interface Comparable. Note that Comparable has a method compareTo(). compareTo() must be used in programming logic you will write in a method called isInAscendingOrder() (more about isInAscendingOrder() is mentioned further down in the lab description). You can find a brief summary...
Question: The purpose for this project is to reinforce the knowledge from Chapter Two of the...
Question: The purpose for this project is to reinforce the knowledge from Chapter Two of the textbook. The ... The purpose for this project is to reinforce the knowledge from Chapter Two of the textbook. The students will practice how to implement stack and queue data structure using list structure, for instance, ArrayList. The students will also apply stack and queue in real project, for instance, to check if a string is a palindrom. Tasks:      1. Use ArrayList to...
IN JAVA Minimal Documentation Required (no javadoc) Purpose The purpose of this assignment is to introduce...
IN JAVA Minimal Documentation Required (no javadoc) Purpose The purpose of this assignment is to introduce you to basic operations on a linked list. Specifics Design a program that generates a linked list of randomly generated Integer objects. Present a menu at program start that gives the user the following options (most of these options will have corresponding methods in a Linked List class): 1. Create a new list. The size will be specified by the user, make sure a...
Write the code in C++. Write a program to implement Employee Directory. The main purpose of...
Write the code in C++. Write a program to implement Employee Directory. The main purpose of the class is to get the data, store it into a file, perform some operations and display data. For the purpose mentioned above, you should write a template class Directory for storing the data empID(template), empFirstName(string), empLastName(string), empContactNumber(string) and empAddress(string) of each Employee in a file EmployeeDirectory.txt. 1. Write a function Add to write the above mentioned contact details of the employee into EmployeeDirectory.txt....
The purpose of this problem set is to reinforce your knowledge of some basic chemical concepts...
The purpose of this problem set is to reinforce your knowledge of some basic chemical concepts that are important for the origin of the elements. 1. Use the abundances of the stable isotopes of strontium and the masses of these nuclides (found at http://atom.kaeri.re.kr/nuchart/) to calculate the atomic weight of strontium. Compare the value that you get with the value shown in the periodic table found at http://www.rsc.org/periodic-table. Show your work. 2. Consult the chart of the nuclides (http://atom.kaeri.re.kr/nuchart/ )...
The purpose of this assignment is to reinforce Ada concepts. Define a Complex-numbers package includes the...
The purpose of this assignment is to reinforce Ada concepts. Define a Complex-numbers package includes the following operations: Addition Subtraction Multiplication Division A “main program” needs to create one or more complex numbers, perform the various arithmetic operations, and then display results. Develop the program in ADA code with several packages. Write a short report that documents all work done, including the overall design, explanation of the implementation, the input data used to run the program, the output of the...
Can anyone make a documentation and comments for the following code? Documentation in doxgen format please....
Can anyone make a documentation and comments for the following code? Documentation in doxgen format please. Thank you! And simple comments for the code. Thank s. template <typename T> bool LinkedList<T> :: search(const T& item) const { // if list is not empty display the items Node<T>* current = first; while (current != NULL) { if (current->info == item) { return true; } current = current->link; } return false; } template <typename T> void LinkedList<T> :: deleteNode(const T& item) {...
Modularity Note: The documentation you’ll be looking at for this part of the lab was written...
Modularity Note: The documentation you’ll be looking at for this part of the lab was written for professional programmers, not programming novices, so it may include a number of references to complex technical topics or details. Don’t be surprised, discouraged, or concerned if parts of it don’t make a lot of sense right now; much of it will become clearer as the semester progresses. For now, just do the best you can to look for information that you can use...
How does a company's code of ethics reinforce its Corporate Social Responsibility?
How does a company's code of ethics reinforce its Corporate Social Responsibility?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT