0% found this document useful (0 votes)
69 views

Department of Engineering Design & Manufacture: Computer Programming (KCEC 1108)

This document contains a student's submission for 3 programming questions. It includes the student's name, matrix number, and submission date. Question 1 asks the student to write a program to input and display 5 names. Question 2 asks the student to sort a list of 5 input names alphabetically. Question 3 asks the student to create a class to input student scores, calculate the average score, and output student names, scores, and grades.

Uploaded by

Sham Rizz
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views

Department of Engineering Design & Manufacture: Computer Programming (KCEC 1108)

This document contains a student's submission for 3 programming questions. It includes the student's name, matrix number, and submission date. Question 1 asks the student to write a program to input and display 5 names. Question 2 asks the student to sort a list of 5 input names alphabetically. Question 3 asks the student to create a class to input student scores, calculate the average score, and output student names, scores, and grades.

Uploaded by

Sham Rizz
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

DEPARTMENT OF

ENGINEERING
DESIGN & MANUFACTURE

COMPUTER PROGRAMMING
(KCEC 1108)

NAME : SHAMSUL RIDZUAN BIN SOED


MATRIX NO. : KEP 100032
SUBMISSION DATE : APRIL 15TH, 2011
QUESTION 1
#include<iostream>
#include<string>

using namespace std;

int main()
{
string name[5];
char ans;

do
{
cout<<endl;
cout<<"********************\n";
cout<<"PLEASE ENTER 5 NAMES\n";
cout<<"********************\n\n";

for(int i=1;i<=5;i++)
getline(cin, name[i]);
cout<<"\nLIST OF THE NAMES ARE :\n";

for(int i=1;i<=5;i++)
{
cout<<i<<"\t"<<name[i]<<endl;
}
cout<<endl;
cout<<"DO YOU WANT TO CONTINUE (y/n) :";
cin>>ans;
}
while(ans=='y');

}
QUESTION 2
#include<iostream>
#include<string>

using namespace std;

void list(string *x, string *y)


{
if(*x>*y)
{
string enter;
enter = *x;
*x = *y;
*y = enter;
}
}
int main()
{
const int n=5;
cout<<"\t--------------------"<<endl;
cout<<"\tPlease Enter 5 Names"<<endl;
cout<<"\t--------------------"<<endl<<endl;

string name[n];

for(int i=0;i<n;i++)
{
getline (cin, name[i]);
}
cout<<endl;

for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
list (&name[i], &name[j]);
}

cout<<"The Names That You Entered Are: "<<endl<<endl;

for(int i=0; i<n; i++)


cout<<i+1<<"\t"<<name[i]<<endl;
cout<<endl;

return 0;
}
QUESTION 3
#include<iostream>
#include<iomanip>
#include<string>

using namespace std;

class studentscore
{
private:
string name[50];
int score[50];
int number;

public:
void inputscore()
{
cout<<"Please Enter The Number of Student\n";
cin>>number;
cout<<endl;
cin.ignore(' ','\n');

for (int i=0; i<number; i++)


{
cout<<"Student Names:\n";
if (i!=0) cin.ignore(' ','\n');
getline(cin, name[i]);
cout<<endl;
cout<<"Marks : ";
cin>>score[i];
cout<<endl;
}
}

double average()
{
double sum=0;
for (int i=0; i<number; i++)
sum+=score[i];
return sum/number;
}

void print()
{
cout<<"Name"<<setw(25)<<"Marks"<<setw(12)<<"Grade\n";
for (int i=0; i<number; i++)
{
int m=i+1;
cout<<m<<"."<<left<<setw(21)<<setiosflags(ios::fixed|
ios::showpoint)<<name[i]<<setw(12)<<score[i]<<" ";
if(score[i]>80 && score[i]<=100)
cout<<"A\n";
else if(score[i]>=60 && score[i]<=79)
cout<<"B\n";
else if(score[i]>=40 && score[i]<=59)
cout<<"C\n";
else if(score[i]>=20 && score[i]<=39)
cout<<"D\n";
else if(score[i]>=0 && score[i]<=19)
cout<<"F\n";
}
}
};

int main()
{
studentscore scorelist1;

scorelist1.inputscore();
cout<<endl;
scorelist1.print();
cout<<endl;
cout<<"The Average Score of the students
are:"<<setprecision(2)<<scorelist1.average()<<endl;
}

You might also like