Josh
Josh
OF SOUTHERN PHILIPPINES
Alubijid | Cagayan de Oro | Claveria | Jasaan | Oroquieta | Panaon
Do the following.
1. Create a program where it asks for 10 numbers from the user and store it in an
array. The program will then ask or give options for the user as to what to do
next. The options are as follows:
a. Display elements from minimum to maximum
b. Display elements from maximum to minimum
c. Display the maximum number among the elements
d. Display the minimum number among the elements
e. Display both maximum and minimum numbers
f. Display odd and even numbers
g. Exit the program
The program will not end until the user chooses option G, otherwise the program
will always display the options every after execution of an option.
2. Create a program where it will use a structure. The program will ask user for the
number of entries to be stored. The data to be store would be name, age, gender.
After all entries are entered, it will then display all the stored entries.
1.
#include <iostream>
#include <algorithm>
#include <stdlib.h>
using namespace std;
int main(){
int arr[Size];
cout<<"Enter 10 numbers: "<<endl;
for (int i = 0; i < Size; i++){
cin>>arr[i];
}
system("cls");
system("color a");
cout<<"--------------------------------------------------------\n";
cout<<"Entered numbers: ";
for (int i = 0; i < Size; i++){
cout<<arr[i]<<" ";
}
cout<<"\n-------------------------------------------------------\n\n";
cout<<"========================================================\n";
cout<<"CHOOSE WHAT TO DO WITH THOSE NUMBERS"<<endl;
char choice;
while(true){
cout<<"a. Display elements from minimum to maximum"<<endl;
cout<<"b. Display elements from maximum to minimum"<<endl;
cout<<"c. Display the maximum number among the elements"<<endl;
cout<<"d. Display the minimum number among the elements"<<endl;
cout<<"e. Display both maximum and minimum number among the elements"<<endl;
cout<<"f. Displayodd and even numbers"<<endl;
cout<<"g. exit the program"<<endl<<endl;
cout<<"Enter your choice (a,b,c,...,g): ";
cin>>choice;
system("cls");
switch(choice){
case 'a':
system("cls");
cout<<"*****************"<<endl;
cout<<"initializing..."<<endl;
cout<<"output:"<<endl;
system("color a");
displayMintoMax(arr);
cout<<"--------------------------------------------------------\n\n";
break;
case 'b':
system("cls");
cout<<"*****************"<<endl;
cout<<"initializing..."<<endl;
cout<<"output:"<<endl;
system("color b");
displayMaxtoMin(arr);
cout<<"--------------------------------------------------------\n\n";
break;
case 'c':
system("cls");
cout<<"*****************"<<endl;
cout<<"initializing..."<<endl;
cout<<"output:"<<endl;
system("color c");
maxNumber(arr);
cout<<"--------------------------------------------------------\n\n";
break;
case 'd':
system("cls");
cout<<"*****************"<<endl;
cout<<"initializing..."<<endl;
cout<<"output:"<<endl;
system("color d");
minNumber(arr);
cout<<"--------------------------------------------------------\n\n";
break;
case 'e':
system("cls");
cout<<"*****************"<<endl;
cout<<"initializing..."<<endl;
cout<<"output:"<<endl;
system("color e");
maxMinNumbers(arr);
cout<<"--------------------------------------------------------\n\n";
break;
case 'f':
system("cls");
cout<<"*****************"<<endl;
cout<<"initializing..."<<endl;
cout<<"output:"<<endl;
system("color f");
oddEvenNumbers(arr);
cout<<"--------------------------------------------------------\n\n";
break;
case 'g':
exit(false);
default:
cout<<"******************"<<endl;
cout<<"Invalid Choice"<<endl;
break;
}
}
system("pause");
return 0;
}
2.
#include <iostream>
#include <windows.h>
using namespace std;
struct myData{
private:
char gender;
public:
string name;
int age;
displayInformation();
}
char getGender(){
return gender;
}
void setGender(char aG){
if(aG == 'M' || aG == 'F' || aG == 'O'){
gender = aG;
}else{
gender = '!';
}
}
void displayInformation(){
cout<<"=================="<<endl;
cout<<"Name: "<<name<<endl;
cout<<"Age: "<<age<<endl;
cout<<"Gender: "<<gender<<endl;
cout<<"=================="<<endl;
}
};
int main(){
int entries;
cout<<"How many Entries do you want to store? _";
cin>>entries;
myData Datas[entries];
system("cls");
system("color a");
for(int i = 0; i < entries; i++){
cout<<endl;
Datas[i].displayInformation();
}
return 0;
}
NOTE: