1- Write a program that asks the user to enter 3 numbers than displays the following menu:
c- Display the numbers sorted in decreasing order
d- Display odd numbers
e- Display even numbers
f- Write the numbers in a file.
The program then asks the user to enter his choice and executes the required task.
If the user enters option ‘f’ ,the program will have to ask the user to enter the name of the file.
Important :
1- Use a switch to handle the different options of the menu.
2- All numbers need to be displayed with 2 decimals precision.
1
Expert's answer
2012-11-26T08:58:52-0500
#include <iostream> #include <fstream> using namespace std;
void bubbleSort(); int arrayofnumbers[3]; int main() { char ch=' '; for(int i=0;i<3;i++){ printf("Enter number %d: ",i+1); scanf("%d",&arrayofnumbers[i]); } do{ printf(" c - Display the numbers sorted in decreasing order "); printf("d - Display odd numbers "); printf("e - Display even numbers "); printf("f - Write the numbers in a file. "); printf("q - Exit "); printf("Select one item: "); ch=getchar(); ch=getchar(); switch(ch){ case 'c': bubbleSort(); printf("The numbers sorted in decreasing order: "); for(int i=2;i>=0;i--){ printf("%d,",arrayofnumbers[i]); } break; case 'd': printf("Odd numbers: "); for(int i=0;i<3;i++){ if(arrayofnumbers[i]%2==1){ printf("%d,",arrayofnumbers[i]); } } break; case 'e':
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment