hey every one..
I have tried my code but it has some errors and mistakes!!!!
any one could help me solve this problem,,,please resend the code with corrections
Write a user-friendly C++ program that allows a user to select repeatedly an operation to be performed from a displayed menu of actions. The menu includes the following items:
1. Simple Statistics
2. Vector Addition
3. Dot Product
4. Exit
The menu actions are described by the following points:
1- Simple Statistics: This action includes finding the average, and standard deviation of a list of data items. The option should allow the user to specify the name of a file from which the data are read into an array. All the results of this option are displayed on the screen.
2- Vector Addition: This action allows the user to enter the name of a file from which two vectors, V1 and V2, of equal size N are read. Accordingly, the two vectors are added, and displayed along with the resultant vector on the screen. Your program should check that the two added vectors are of the same size. Otherwise, the program should display a message and allow the user to make another choice from the menu.
3- Dot Product: This action is similar to the Vector Addition in terms of input, output, and checking validity of the vector operands.
4- Exit: This action terminates the program.
Your program should include at least the following functions:
1. A function, called ReadVector(), which reads a vector of any size from a given file name, and returns the vector and its size to the caller. The function prototype is defined as follows:
void ReadVector(double V[ ], int &size, ifstream infile);
2. A function, called DisplayMenu(), which displays the menu and returns the user%u2019s choice as an integer value between 1 and 4. The function prototype is defined as follows:
int DisplayMenu (void);
3. A function, called VectorAdd(), which performs the addition of two vectors, A and B, and returns the resultant vector, C. The function prototype is defined as follows:
For one, the "selection" variable is never allocated- you simply state its value and throw it into a switch. Yes, you returned the value of selection in displaymenu, but since you didn't actually store that returned value into selection, the input was meaningless. Second, your "statistics" case does absolutely nothing other than display the words that precede the statistics, then not actually call any functions. In your vector case, the arrays that you are reading from are also not allocated (empty brackets), not to mention that size is never defined as well, so those for loops will go on to whatever ungodly value is stuck in there. And, since the arrays were never allocated, the compiler would allow that... which could cause some serious issues. Your case 3, dot-product of vectors, also has the same issues as case 2... plus calling the dot product function while passing to it another undefined number, result. Your case 4 is pointless, and there is no default case in that switch. Also, the second and third cases don't break. Immediately following the switch is an infinite loop (you can't have a while loop where selection != 4 if selection never changes in that loop). Worse, your dotproduct function has the value (which, due to not being stated, is some gibberish number) sent to it as the address of result. ReadVector is also never used once, nor are any of your statistics functions. Also, your method for checking if the two vectors have the same size is foolish- you throw in an unspecified value into two arrays of unallocated memory, and compare the two. That tells you nothing about their size. In your un-used statistics file, you forgot to put braces around the first for loop.
However, if you want to know just what the compilation error is, you forgot to include cmath when you used the sqrt function.