Comp242-hw3 - } ages[i]=StudentAge }...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 #include <iostream> #include <cstdlib> using namespace std double compute_average_age (const int ages[], int N) int minimum_gender_age (const int ages[], const char genders[], int N, char gend) int ages[20] char genders[20] int N char StudentGender int StudentAge int totalAge int main(){ cout<<"Enter the student number(can be at most 20): " cin>>N while(N > 20 || N<0){ cout<<"Invalid Input!" cout<<"Enter the student number(can be at most 20): " cin>>N } for(int i=1 i<= N i++){ cout<<"Enter gender of student "<< i <<":" cin>>StudentGender cout<<"Invalid Gender! Enter gender of student "<< i<<":" cin>>StudentGender } genders[i]=StudentGender cout<<"Enter age of student"<<i<<":" cin>>StudentAge while(StudentAge<10 || StudentAge>40){ cout<<"Invalid Age!Enter age of student "<<i<<":"
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Sheet1 Page 2 cin>>StudentAge
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } ages[i]=StudentAge } cout<<"Analysis Results:"<<endl cout<<"-----------------"<<endl cout<<"Average Age:"<<compute_average_age(ages,N)<<endl cout<<"Minimum female age:"<<minimum_gender_age(ages,genders,N,'F')<<endl cout<<"Minimum male age:"<<minimum_gender_age(ages,genders,N,'M')<<endl system("pause") } double compute_average_age (const int ages, int N){ for(int j=1 j<=N j++){ totalAge+=ages[j] } return (double)totalAge/(double)N } int minimum_gender_age (const int ages, const char genders, int N, char gend){ int femaleMin=999 int maleMin=999 for(int i=1 i<=N i++){ if(genders[i]=='F') { if(ages[i]<femaleMin) { femaleMin=ages[i] } } else if(genders[i]=='M') Sheet1 Page 3 { if(ages[i]<maleMin) { maleMin=ages[i] } } } if (gend=='F') return femaleMin else return maleMin }...
View Full Document

This note was uploaded on 04/18/2010 for the course COMPUTER E Comp242 taught by Professor I.oyman during the Spring '10 term at Koç University.

Page1 / 3

Comp242-hw3 - } ages[i]=StudentAge }...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online