Sie sind auf Seite 1von 9

QUESTION 3:

#include<iostream>
#include<string.h>
using namespace std;

struct teacher{
char teacherName[30];
char schoolName[30];
char subjectTaught[2][20];
int yearExperience;
float salary;
};
teacher teachers[3];

int main()
{
bool foundName = false;
char searchName[30]={"VALERIE SOON LAI MENG"};

cout<<"PLEASE ENTER ALL OF THIS INFORMATION IN CAPITAL LETTER :)"<<endl;


cout<<"\n---------------------------------------------------------" <<endl;
for(int i=0; i<3; i++)
{
cout<<"\n";
cout<<"Enter the teacher's name: ";
cin.ignore();
cin.getline(teachers[i].teacherName, 30);
cout<<"Enter the school's name: ";
cin.ignore();
cin.getline(teachers[i].schoolName, 50);
for(int j=0; j<2; j++)
{
cout<<"Enter the subject's taught: "<<j+1<<". ";
cin.getline(teachers[i].subjectTaught[j], 20);
}
cout<<"Enter the year experience: ";
cin>>teachers[i].yearExperience;
cout<<"Enter the salary: RM";
cin>>teachers[i].salary;
cout<<endl;
}

cout<<"-----------------------------------------------"<<endl;
cout<<"Teachers who teach English & Science subject: \n";
for(int a=0; a<3; a++)
{
if(strcmp(teachers[a].subjectTaught[0], "ENGLISH")==0 ||
strcmp(teachers[a].subjectTaught[1], "ENGLISH")==0
|| strcmp(teachers[a].subjectTaught[0], "SCIENCE")==0 ||
strcmp(teachers[a].subjectTaught[1], "SCIENCE")==0)
cout<<a+1<<". "<<teachers[a].teacherName<<endl;
}

int count10=0;
for(int b=0; b<3; b++){
if(teachers[b].yearExperience>10)
count10++;
}
cout<<"\n\nThe numbers of teachers who has more than 10 years of experience is:
"<<count10<<endl;

for(int c=0; c<3; c++){


if(strcmp(teachers[c].teacherName, searchName)==0){
strcpy(teachers[c].teacherName, "BADARIAH BABA");
foundName=true;
break;
}
}
if(foundName==true)
cout<<"\nTeacher VALERIE SOON LAI MENG is found in the record and updated name
with BADARIAH BABA";
else
cout<<"\n\nVALERIE SOON LAI MENG is not found in the system";
}
OUTPUT:
QUESTION 2:

#include<iostream>
using namespace std;

struct mpv
{
char manufacturer[30];
float price;
int yearManufactured;
int numOfSeat;
float roadtax;
};
mpv vehicles[3];

int getData(mpv vehicles[]);


int findlow(mpv vehicles[]);

int main()
{
getData(vehicles);
findlow(vehicles);
}

int getData(mpv vehicles[])


{
for(int i=0; i<3; i++)
{
cout<<"Enter the manufacturer: ";
cin.ignore();
cin.getline(vehicles[i].manufacturer, 30);
cout<<"Enter the price: RM";
cin>>vehicles[i].price;
cout<<"Enter the manufactured year: ";
cin>>vehicles[i].yearManufactured;
cout<<"Enter the number of seat(s): ";
cin>>vehicles[i].numOfSeat;
cout<<"Enter the road tax: RM";
cin>>vehicles[i].roadtax;
cout<<endl;
}

int findlow(mpv vehicles[])


{
int indexL;
float low=vehicles[0].price;
for(int k=0; k<3; k++)
{
if(vehicles[k].price<low)
{
low=vehicles[k].price;
indexL=k;
}
}
cout<<"The lowest price of multipurpose vehicle is from manufacturer
"<<vehicles[indexL].manufacturer;
}
OUTPUT:
QUESTION 1:

#include <iostream>
using namespace std;

const int row=3;


const int col=4;
int ratings[row][col];

int insertInput(int rate[][col], int rSize);


int leastRating(int rate[][col], int rSize);
void findTheBestmovie(int rate[][col], int rSize);

int main()
{
insertInput(ratings,row);
leastRating(ratings,row);
findTheBestmovie(ratings,row);
}

int insertInput(int rate[][col], int rSize)


{
for(int r=0; r<rSize; r++)
{
cout<<"\nReview"<<r+1<<" ";
for(int c=0; c<col; c++)
{
cin>>rate[r][c];
}
}
}

int leastRating(int rate[][col], int rSize)


{
int indexR,indexC;
int lowest=rate[0][0];
for(int r=0; r<rSize; r++)
{
for(int c=0; c<col; c++)
{
if(rate[r][c]<lowest)
{
lowest= rate[r][c];
indexR= r;
indexC= c;
}
}
}
cout<<"Lowest Movie Rating is Movie "<<indexC+1<<" by Reviewer "<<indexR+1<<endl;
}
void findTheBestmovie(int rate[][col], int rSize)
{
double avgAll[col],highestAvg;
int sum,indexhigh;
for(int c=0; c<col; c++)
{
sum=0;
for(int r=0; r<rSize; r++)
{
sum+=rate[r][c];
}
avgAll[c]=sum/3;
}
highestAvg=avgAll[0];
for(int c=0; c<col; c++)
{
if(avgAll[c]>highestAvg)
{
highestAvg=avgAll[c];
indexhigh=c;
}

}
cout<<"Best movie:" <<indexhigh+1<<" with average rating "<<avgAll[indexhigh]<<endl;
}
OUTPUT:

Das könnte Ihnen auch gefallen