Question

In: Computer Science

#include <iostream> #include <cmath>using namespace std; const int A_CONSTANT = 3; void functionA(int a[], int aNumber);...

#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 << "*";

  

}

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.

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.

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.

The reason why I wrote the question 3 times is because I want you to READ the question as the last person failed to do so, Please comment out the code

thanks

Solutions

Expert Solution

Proper comments has been added, white spaces and indentation for more readability is also done:

See the images for more understanding in Readability:

Code:

#include <iostream> //Include the Header library provides basic input and output services.

#include <cmath> //declares a set of functions to perform mathematical operations

using namespace std; // define the context in which names are defined.(it defines the scope)

const int A_CONSTANT = 3; //declare a integer constant and assigned the value

void functionA(int a[], int aNumber); //function declaration: named functionA which takes integer number and integer array argument having void as a return type

void functionB(int a[], int anotherNumber); //function declaration: named functionB which takes integer number and integer array argument having void as a return type

void functionC(const int anArray[], int aNumber); //function declaration: named functionC which takes integer number and constant integer array argument having void as a return type

void functionD(int &sum);//function declaration: named functionD which takes integer argument "&" denotes a reference instead of a pointer to an objec

int functionE(double number); //function declaration: named functionE which takes double datatype argument(parameter) with intger return type.

void functionF(int n); //function declaration: named functionF which takes integer as an argument and void return type

int main( ){ //Main Method declaration

int production[A_CONSTANT]; //integer array declaration which takes A_CONSTANT as a size of array

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

functionA(production, A_CONSTANT); //calling Function functionA and passing the parameters

functionB(production, A_CONSTANT); //calling Function functionB and passing the parameters

functionC(production, A_CONSTANT); //calling Function functionC and passing the parameters

return 0; //The return 0 means success and returning a non-zero number means failure.
  
} //main method ended

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

for (int someNumber = 1;someNumber <= aNumber; someNumber++){
cout << endl << "Enter production data for plant number " << someNumber << endl; //endl denotes the nextline
functionD(a[someNumber - 1]);//functio calling
}

}//end of functionA

void functionD(int& sum){ //method functionD

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

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

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

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


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

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

Screenshots:

I hope this will help you if not please comment below i will help you!!

Please do not forget to Upvote the answer!!

Happy Learning!!:)


Related Solutions

#include <iostream> using namespace std; const int DECLARED_SIZE = 10; void fillArray(int a[], int size, int&...
#include <iostream> using namespace std; const int DECLARED_SIZE = 10; void fillArray(int a[], int size, int& numberUsed) { cout << "Enter up to " << size << " nonnegative whole numbers.\n" << "Mark the end of the list with a negative number.\n"; int next, index = 0; cin >> next; while ((next >= 0) && (index < size)) { a[index] = next; index++; cin >> next; } numberUsed = index; } int search(const int a[], int numberUsed, int target) {...
in C++, #include<iostream> using namespace std; const int NUM = 10; void prepareArr(int a[]); int countEven...
in C++, #include<iostream> using namespace std; const int NUM = 10; void prepareArr(int a[]); int countEven (int b[]); int main() { int arr[NUM]; // write a statement to call prepareArr to set values for the array // write a statement to call countEven and print the data returned for(int i = 0; i<NUM; i++) cout << arr[i] <<" "; cout <<endl; return 0; } void prepareArr(int a[]) { //randomly generate NUM integers in the range [0,99] and save them in...
#include<iostream> #include<cmath> using namespace std; int p = 7; void main() { extern double var ;...
#include<iostream> #include<cmath> using namespace std; int p = 7; void main() { extern double var ; int p = abs(-90); cout << ::p + p - var << endl; system("pause"); } double var = 5.5;
#include<vector> #include<iostream> using namespace std; void println(const vector<int>& v) {    for (int x : v)...
#include<vector> #include<iostream> using namespace std; void println(const vector<int>& v) {    for (int x : v)        cout << x << " ";    cout << endl; } void println(const vector<string>& v) {    for (const string& x : v)        cout << " "<< x << " ";    cout << endl; } int main() {    vector<int> v0;    cout << "An empty vector of integers: ";    println(v0);    vector<int> v1(3);    cout << "A...
#include <iostream> #include <fstream> #include <string> using namespace std; const int QUIZSIZE = 10; const int...
#include <iostream> #include <fstream> #include <string> using namespace std; const int QUIZSIZE = 10; const int LABSIZE = 10; const int PROJSIZE = 3; const int EXAMSIZE = 3; float getAverage(float arr[], int size) { float total = 0; for (int i = 0; i < size; i++) { total += arr[i]; } return total/size; } // the following main function do.... int main() { ifstream dataIn; string headingLine; string firstName, lastName; float quiz[QUIZSIZE]; float lab[LABSIZE]; float project[PROJSIZE]; float midExam[EXAMSIZE];...
#include <cstring> #include <stdio.h> #include <iostream> using namespace std; int main() {        const int...
#include <cstring> #include <stdio.h> #include <iostream> using namespace std; int main() {        const int SIZE = 20;     char str[SIZE];     char str1[SIZE];     int n;     int k =1;        printf("Enter a word: \n");     fgets(str,SIZE,stdin);     printf("Enter another word: \n");     fgets(str1,SIZE,stdin);        if (str1[strlen(str1) - 1] == '\n')     {         str1[strlen(str1)-1] = '\0';     }     if (str[strlen(str) - 1] == '\n')     {         str[strlen(str)-1] = '\0';     }      ...
#include<iostream> using namespace std; class point{ private: int x; int y; public: void print()const; void setf(int,...
#include<iostream> using namespace std; class point{ private: int x; int y; public: void print()const; void setf(int, int); }; class line{ private: point ps; point pe; public: void print()const; void setf(int, int, int, int); }; class rectangle{ private: line length[2]; line breadth[2]; public: void print()const; void setf(int, int, int, int, int, int, int, int); }; int main(){ rectangle r1; r1.setf(3,4,5,6, 7, 8, 9, 10); r1.print(); system("pause"); return 0; } a. Write function implementation of rectangle, line and point. b. What is...
#include<iostream> using namespace std; void calcSumAndDiff(int ,int, int &, int &); void calcSumAndDiff(int n1,int n2, int...
#include<iostream> using namespace std; void calcSumAndDiff(int ,int, int &, int &); void calcSumAndDiff(int n1,int n2, int &sum, int &diff){ sum = n1 + n2; diff = n1 - n2; } int main() { int n1,n2,sum,diff; n1=30;n2=10; calcSumAndDiff(n1,n2,sum,diff); cout<<"Sum is :"<<sum<<endl; cout<<"Diff is:"<<diff<<endl; system("pause"); }
#include <iostream> #include <string> #include <ctime> using namespace std; void displayArray(double * items, int start, int...
#include <iostream> #include <string> #include <ctime> using namespace std; void displayArray(double * items, int start, int end) { for (int i = start; i <= end; i++) cout << items[i] << " "; cout << endl; } //The legendary "Blaze Sort" algorithm. //Sorts the specified portion of the array between index start and end (inclusive) //Hmmm... how fast is it? /* void blazeSort(double * items, int start, int end) { if (end - start > 0) { int p =...
#include <iostream> #include <string> #include <ctime> using namespace std; void displayArray(double * items, int start, int...
#include <iostream> #include <string> #include <ctime> using namespace std; void displayArray(double * items, int start, int end) { for (int i = start; i <= end; i++) cout << items[i] << " "; cout << endl; } //The legendary "Blaze Sort" algorithm. //Sorts the specified portion of the array between index start and end (inclusive) //Hmmm... how fast is it? /* void blazeSort(double * items, int start, int end) { if (end - start > 0) { int p =...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT