This episode i will provide source code to calculate the performance index (IP) students.
May be useful!...
#include <iostream.h>
#include <stdlib.h>
#include <string.h>
/*
this section is part preprocessor program. Contains the include command, which is used to insert a library file or C++ program. In this program, which is used is a library iostream.h, stdlib.h, string.h
*/
class mhs
{
private:
char name[24];
int jml_mk, nilai[24], sks[24];
public;
mhs();
void input_data();
void name_mhs(char *);
int jum_matkul();
int jum_sks();
float ip();
}
/*
in this section the definition of class mhs, which contains the private and public variable.
In private contains.
1. Array "name" with a length of 24 and of type char ==> to store the name of the student
2. "jml_mk" with an integer data type ==> to keep the number of courses taken
3. An array of "nilai" of length 24 and of type integer ==> to store the value
4. An array of "sks" with a length of 24 and of type integer ==> to keep number of credits
While at the public contains methods such as mhs(), void input_data(), void name_mhs(char *), int jum_matkul(), int jum_sks(), float ip().
*/
mhs::mhs()
{
int i;
strcpy(name,"NULL");
jml_mk=0;
for(i=0, i<24, i++)
{
nilai[i]=5;
sks[i]=0;
}
}
/*this section is a constructor*/
void mhs::input_data()
{
int i;
bf char[30];
/*
bf array of type char with a length of 30 serves as a temporary buffer, for further converted to other data types.
*/
cout<<"Student Name : ";cin.getline(name,24);
/*
this section is to request input from the user in the form of the name of students. The use of getline, so that spaces are not considered by the C++ as an enter key. So the name with two words or more can enter
*/
while((jml_mk<1) || (jml_mk>24))
{
cout<<"The number of subjects : ";cin.getline(bf, 30);
//entering the number of courses, into the buffer while(bf)
jml_mk=atoi(bf);
/*
inserting the contents of the bf into jml_mk with command atoi(alphanumeric to integer). So if you enter a character would be considered as the number 0
*/
if((jml_mk<1) || (jml_mk>24))
cout<<"Enter a number [1-24] : \n\n";
}
/*
if the input is false (more than 24 or less than 1), assuming the maximum a student can take a maximum of 24 credits and 1 credits per course. It will appear warning
*/
for(i=0; i<jml_mk;i++)
{
while((nilai[i]<0) || (nilai[i]>4) || (strlen(bf)>1))
{
cout<<"\nNilai Subject"<<(i+1)<<"=";cin.getline(bf, 30);
}
Inserting the value of course i +1, into a temporary buffer (bf).
nilai[i] = (int) bf [0];
/*Inserting the contents of the bf into the value of [i] with the command int. In order to value the input (form letter) is converted into a numeric code. */
if (nilai[i] <70)
nilai[i] = 69-nilai[i];
else nilai[i] = 101-nilai[i];
if ((nilai[i] <0) | | (nilai[i]> 4) | | (strlen (bf)> 1))
cout <<"Enter the letters [A-E or a-e] : \ n";
}
/*The code number is recognized as a letter from AE / ae. If in addition there will be a warning. */
while ((sks[i] <1) | | (sks[i]> 4))
{
cout <<"The number of course credits" <<(i +1) <<"=";
cin.getline (bf, 30);
/*Entering the number of course credits i +1, into a temporary buffer (bf).\
*/
sks[i] = atoi (bf);
/*Inserting the contents of the bf into jml_mk with command atoi (alphanumeric to integer). So if you enter a character would be considered as the number 0. */
if ((sks[i] <1) | | (sks[i]> 4))
cout <<"Enter a number [1-4] : \ n \ n";
}
}
}
/*If the input is false (more than 4 or less than 1), assuming the maximum credits each course is 4 .. It will appear warning. */
void mhs:: name_mhs (char * s)
{
strcpy (s, name);
}
/*Method to display the names of students*/
mhs int:: jum_matkul ()
{
return (jml_mk);
}
//Method to display the number of subjects
mhs int:: jum_sks ()
{
int i, j;
j = 0;
for (i = 0; i <jml_mk; i + +) j + = credits [i];
return (j);
}
/*Method for calculating the amount of credits. J is a variable to store the number of credits. The program will loop from 0 to many jml_mk. To add to the credits j [i]. */
mhs float:: ip ()
{
int i, j_sks, total;
j_sks = 0;
total = 0;
for (i = 0; i <jml_mk; i + +)
{
j_sks + = [i];
total + = (nilai[i] * sks[i]);
}
return ((float) total / j_sks);
}
/*Method for calculating the IP based on input received program.
• j_sks used to store the number of credits.
• total number of weights used to store values that are multiplied by credits.
The program will loop from 0 to many jml_mk.
And the values shown (IP)) is the sum total in the amount j_sks. */
int main ()
{
int i, jum_mhs;
bf char [30], name [24], user [24];
/*Variable declaration consists of:
1. "I" with an integer data type
2. "Jum_mhs" with an integer data type
= To accommodate the number of students
3. Array "bf" with a length of 30 and of type char.
= To store data temporarily and subsequently converted to another data type.
4. Array "name" with a length of 24 and of type char.
= To store the name of the student.
5. An array of "user" with a length of 24 and char data types.
= To store the name of the user program. */
mhs nodes [10];
//Create a node object based on an existing class.
cout<<"Enter user name:";
cin.getline (user, 24);
cout <<"\ nSelamat come," <<user;
cout <<"at the IP Counting Program student \ n \ n";
//Asking enter the name of the user, and displays them in welcome.
jum_mhs = 0;
while ((jum_mhs <1) | | (jum_mhs> 10))
{
cout <<"Enter Number of Students who will be computed = ";
cin.getline (bf, 30);
//Entering the number of students, into a temporary buffer (bf).
jum_mhs = atoi (bf);
/*Inserting the contents of the bf into jml_mhs with command atoi (alphanumeric to integer). So if you enter a character would be considered as the number 0. */
if ((jum_mhs <1) | | (jum_mhs> 10))
cout <<"Enter a number 1-10 \ n \ n";
}
/*If the input is false (more than 10 or less than 1), it will display a warning.*/
for (i = 0; i <jum_mhs; i + +)
{
cout <<"\ nDATA STUDENTS" <<(i +1) <<endl;
node [i]. input_data ();
}
/*The program will loop from 0 to many jum_mhs, namely input_data calling method. */
cout <<endl <<endl;
cout <<"|--------------------------|-------------|---- -----|----------|" <<endl;
cout <<"| Name of Student | Total | Total | IP |" <<endl;
cout <<"| | Courses | credits | |" <<endl;
cout <<"|--------------------------|-------------|---- -----|----------|" <<endl;
for (i = 0; i <jum_mhs; i + +)
{
cout.setf (ios:: left | ios:: showpoint);
node [i]. name_mhs (name);
cout <<"|";
cout.width (25);
cout <<name;
cout <<"|";
cout.width (7);
cout <<node [i]. jum_matkul ();
cout <<"|";
cout.width (5);
cout <<node [i]. jum_sks ();
cout <<"|";
cout.width (6);
cout.precision (3);
cout <<node [i]. ip ();
cout <<"| \ n";
}
cout <<"|--------------------------|-------------|---- -----|----------|" <<endl;
cout <<endl;
return (0);
}
//Showing the results of the calculations and the data in tabular form
#include <stdlib.h>
#include <string.h>
/*
this section is part preprocessor program. Contains the include command, which is used to insert a library file or C++ program. In this program, which is used is a library iostream.h, stdlib.h, string.h
*/
class mhs
{
private:
char name[24];
int jml_mk, nilai[24], sks[24];
public;
mhs();
void input_data();
void name_mhs(char *);
int jum_matkul();
int jum_sks();
float ip();
}
/*
in this section the definition of class mhs, which contains the private and public variable.
In private contains.
1. Array "name" with a length of 24 and of type char ==> to store the name of the student
2. "jml_mk" with an integer data type ==> to keep the number of courses taken
3. An array of "nilai" of length 24 and of type integer ==> to store the value
4. An array of "sks" with a length of 24 and of type integer ==> to keep number of credits
While at the public contains methods such as mhs(), void input_data(), void name_mhs(char *), int jum_matkul(), int jum_sks(), float ip().
*/
mhs::mhs()
{
int i;
strcpy(name,"NULL");
jml_mk=0;
for(i=0, i<24, i++)
{
nilai[i]=5;
sks[i]=0;
}
}
/*this section is a constructor*/
void mhs::input_data()
{
int i;
bf char[30];
/*
bf array of type char with a length of 30 serves as a temporary buffer, for further converted to other data types.
*/
cout<<"Student Name : ";cin.getline(name,24);
/*
this section is to request input from the user in the form of the name of students. The use of getline, so that spaces are not considered by the C++ as an enter key. So the name with two words or more can enter
*/
while((jml_mk<1) || (jml_mk>24))
{
cout<<"The number of subjects : ";cin.getline(bf, 30);
//entering the number of courses, into the buffer while(bf)
jml_mk=atoi(bf);
/*
inserting the contents of the bf into jml_mk with command atoi(alphanumeric to integer). So if you enter a character would be considered as the number 0
*/
if((jml_mk<1) || (jml_mk>24))
cout<<"Enter a number [1-24] : \n\n";
}
/*
if the input is false (more than 24 or less than 1), assuming the maximum a student can take a maximum of 24 credits and 1 credits per course. It will appear warning
*/
for(i=0; i<jml_mk;i++)
{
while((nilai[i]<0) || (nilai[i]>4) || (strlen(bf)>1))
{
cout<<"\nNilai Subject"<<(i+1)<<"=";cin.getline(bf, 30);
}
Inserting the value of course i +1, into a temporary buffer (bf).
nilai[i] = (int) bf [0];
/*Inserting the contents of the bf into the value of [i] with the command int. In order to value the input (form letter) is converted into a numeric code. */
if (nilai[i] <70)
nilai[i] = 69-nilai[i];
else nilai[i] = 101-nilai[i];
if ((nilai[i] <0) | | (nilai[i]> 4) | | (strlen (bf)> 1))
cout <<"Enter the letters [A-E or a-e] : \ n";
}
/*The code number is recognized as a letter from AE / ae. If in addition there will be a warning. */
while ((sks[i] <1) | | (sks[i]> 4))
{
cout <<"The number of course credits" <<(i +1) <<"=";
cin.getline (bf, 30);
/*Entering the number of course credits i +1, into a temporary buffer (bf).\
*/
sks[i] = atoi (bf);
/*Inserting the contents of the bf into jml_mk with command atoi (alphanumeric to integer). So if you enter a character would be considered as the number 0. */
if ((sks[i] <1) | | (sks[i]> 4))
cout <<"Enter a number [1-4] : \ n \ n";
}
}
}
/*If the input is false (more than 4 or less than 1), assuming the maximum credits each course is 4 .. It will appear warning. */
void mhs:: name_mhs (char * s)
{
strcpy (s, name);
}
/*Method to display the names of students*/
mhs int:: jum_matkul ()
{
return (jml_mk);
}
//Method to display the number of subjects
mhs int:: jum_sks ()
{
int i, j;
j = 0;
for (i = 0; i <jml_mk; i + +) j + = credits [i];
return (j);
}
/*Method for calculating the amount of credits. J is a variable to store the number of credits. The program will loop from 0 to many jml_mk. To add to the credits j [i]. */
mhs float:: ip ()
{
int i, j_sks, total;
j_sks = 0;
total = 0;
for (i = 0; i <jml_mk; i + +)
{
j_sks + = [i];
total + = (nilai[i] * sks[i]);
}
return ((float) total / j_sks);
}
/*Method for calculating the IP based on input received program.
• j_sks used to store the number of credits.
• total number of weights used to store values that are multiplied by credits.
The program will loop from 0 to many jml_mk.
And the values shown (IP)) is the sum total in the amount j_sks. */
int main ()
{
int i, jum_mhs;
bf char [30], name [24], user [24];
/*Variable declaration consists of:
1. "I" with an integer data type
2. "Jum_mhs" with an integer data type
= To accommodate the number of students
3. Array "bf" with a length of 30 and of type char.
= To store data temporarily and subsequently converted to another data type.
4. Array "name" with a length of 24 and of type char.
= To store the name of the student.
5. An array of "user" with a length of 24 and char data types.
= To store the name of the user program. */
mhs nodes [10];
//Create a node object based on an existing class.
cout<<"Enter user name:";
cin.getline (user, 24);
cout <<"\ nSelamat come," <<user;
cout <<"at the IP Counting Program student \ n \ n";
//Asking enter the name of the user, and displays them in welcome.
jum_mhs = 0;
while ((jum_mhs <1) | | (jum_mhs> 10))
{
cout <<"Enter Number of Students who will be computed = ";
cin.getline (bf, 30);
//Entering the number of students, into a temporary buffer (bf).
jum_mhs = atoi (bf);
/*Inserting the contents of the bf into jml_mhs with command atoi (alphanumeric to integer). So if you enter a character would be considered as the number 0. */
if ((jum_mhs <1) | | (jum_mhs> 10))
cout <<"Enter a number 1-10 \ n \ n";
}
/*If the input is false (more than 10 or less than 1), it will display a warning.*/
for (i = 0; i <jum_mhs; i + +)
{
cout <<"\ nDATA STUDENTS" <<(i +1) <<endl;
node [i]. input_data ();
}
/*The program will loop from 0 to many jum_mhs, namely input_data calling method. */
cout <<endl <<endl;
cout <<"|--------------------------|-------------|---- -----|----------|" <<endl;
cout <<"| Name of Student | Total | Total | IP |" <<endl;
cout <<"| | Courses | credits | |" <<endl;
cout <<"|--------------------------|-------------|---- -----|----------|" <<endl;
for (i = 0; i <jum_mhs; i + +)
{
cout.setf (ios:: left | ios:: showpoint);
node [i]. name_mhs (name);
cout <<"|";
cout.width (25);
cout <<name;
cout <<"|";
cout.width (7);
cout <<node [i]. jum_matkul ();
cout <<"|";
cout.width (5);
cout <<node [i]. jum_sks ();
cout <<"|";
cout.width (6);
cout.precision (3);
cout <<node [i]. ip ();
cout <<"| \ n";
}
cout <<"|--------------------------|-------------|---- -----|----------|" <<endl;
cout <<endl;
return (0);
}
//Showing the results of the calculations and the data in tabular form
0 comment:
Post a Comment