Lab 0: Clarification & Guide Needed

  • C/C++
  • Thread starter needOfHelpCMath
  • Start date
  • Tags
    Lab
In summary, the conversation discussed the attachment for a lab and clarified that the individual was going in the right direction. Some minor modifications were suggested, such as assigning values to variables, returning values in functions, and adding a menu function. The individual was also encouraged to continue their work and wished good luck.
  • #1
needOfHelpCMath
72
0
View attachment 6372

Here is the attachment for my lab and just need some clarification and guide if I am going in the right direction?
HTML:
// Januaray 24 2017
// Lab 0

#include <iostream>
#include <string>
#include <cmath>

using namespace std;

const int COLUMS = 5;
int a;

void findMin(int a[], int size) 
{
	int min = a[0]; // temp variable...array don't use dot 
	
	for (int i = 0; i < size; ++i) 
	{
	
		if (min > a[i]) 
		
		{
			min = a[i];
		}
		
	}

	return min;
}

void calulate(string exp) 
{
	// check for a plus
		// if found add the two numbers
	// check for minus
		// if found, subtract the two numbers
	// check for a times
		// if found, multiply the two numbers
	// check for divide
		// if found, divide the to numbers
	// if nothing is found
		// return
return;     
}

double computeAvg(int a[][COLUMS], int row, int column) 
{
	double sum = 0;
		
     for (int i = 0; i < row; ++i)
     {
     	for (int j = 0; j < column; ++j)
     	{
     		sum += a[i][j];
		}
	 }
     
return sum / (row * column);
}

void sqaureByValue(int squareNum)
{
     cout << pow(sqaureNum) << endl;
     
return;
}

void squareByReference(int& squareRef)
{
	cout << sqaureRef << endl;
	
return;
}

void menu(int numNeg) 
{
	int i = 0;
	
	for (i = 0; i >= numNeg; --i)
	{
		cout << numNeg;
	}
}
int main()
{
    
    int a = 0;
    
   while ( a != -1) {
         cin >> a;
       
   
   switch (a) {
          
          case 1:
               findMin(int a[], int size);
          break;
               
          case 2:
               calulate(string exp);
          break;
                        
          case 3:
               calulate(a[], size);
          break;
                
          case 4:
               computeAvg(a[], row, column);
          break;
               
          case 5:
               squareByValue
          break;
               
          case 6:
               squareByReference
          break;
                }  
}

}
 

Attachments

  • Lab1.pdf
    73 KB · Views: 54
Technology news on Phys.org
  • #2
Yes, you are going in the right direction. Your code is mostly correct. However, there are a few things that need to be fixed. First, you have declared a variable called 'a', but you have not assigned it a value. You also need to assign a value to the constant 'COLUMNS'. Secondly, in the 'findMin()' function, you should return the minimum value, rather than just printing it out. Thirdly, in the 'calculate()' function, you need to actually do the calculations and return the result. Fourthly, in the 'computeAvg()' function, you need to divide the sum by the total number of elements in the array, rather than just the number of rows and columns. Finally, in the 'sqaureByValue()' and 'squareByReference()' functions, you need to actually pass in the argument and perform the calculation to find the square.You should also add a 'menu()' function, which will allow the user to choose the option they want to use. I hope this helps. Good luck!
 

Related to Lab 0: Clarification & Guide Needed

1. What is the purpose of Lab 0?

The purpose of Lab 0 is to provide clarification and guidance for the upcoming labs in the course. It serves as an introduction to the lab format and expectations.

2. Do I need to complete Lab 0 before starting the other labs?

Yes, it is highly recommended to complete Lab 0 before starting the other labs as it will help you understand the format and expectations for the rest of the labs.

3. How long will it take to complete Lab 0?

The time it takes to complete Lab 0 may vary depending on your familiarity with the lab format and the specific instructions for this lab. It is estimated to take approximately 1-2 hours to complete.

4. Are there any specific resources needed for Lab 0?

No, there are no specific resources needed for Lab 0. However, it is recommended to have access to a computer and internet connection to complete the lab.

5. Is there a deadline for completing Lab 0?

Yes, the deadline for completing Lab 0 will be specified by your instructor. It is important to complete the lab before the deadline to ensure you have enough time to complete the subsequent labs.

Similar threads

  • Programming and Computer Science
Replies
15
Views
2K
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
22
Views
2K
  • Programming and Computer Science
Replies
1
Views
908
  • Programming and Computer Science
Replies
10
Views
1K
  • Programming and Computer Science
Replies
23
Views
1K
  • Programming and Computer Science
Replies
20
Views
1K
  • Programming and Computer Science
Replies
5
Views
932
  • Programming and Computer Science
Replies
25
Views
2K
  • Programming and Computer Science
3
Replies
75
Views
4K
Back
Top