Sie sind auf Seite 1von 3

Downpayment Breakdown upon Enrollment

Problem
A program that will display how the downpayment be broken down into tuition fee and
different miscellaneous fees upon enrollment.
Program
#include <iostream>
#include <math.h>
using namespace std;
void main()
{
int num1;
double num2,num3,num4,num5,num6;
char name1 [20],name2[20],name3[4];
cout<<"DOWNPAYMENT ALLOCATION"<<endl;
cout<<"Last Name: ";
cin.getline (name1,20);
cout<<"First Name: ";
cin.getline (name2,20);
cout<<"Middle Initial: ";
cin.getline (name3,4);
cout<<"Downpayment: ";
cin>>num1;
cout<<"-----------------------------------------"<<endl;
cout<<"BREAKDOWN OF DOWNPAYMENT"<<endl;
cout<<" "<<endl;
num2=num1*0.4;
cout<<"Tuition Fee: "<<num2<<endl;
cout<<" "<<endl;
cout<<"Miscellaneous Fee"<<endl;
num3=num1*0.25;
cout<<"Laboratory Fee: "<<num3<<endl;
num4=num1*0.1;
cout<<"Internet Fee: "<<num4<<endl;
num5=num1*0.15;
cout<<"Library: "<<num5<<endl;
num6=num1*0.1;
cout<<"Test Papers: "<<num6<<endl;
cout<<"Congratulations "<<name2<<" "<<name3<<". "<<name1<<"! You are now
Enrolled!"<<endl;
}
Output

Discussions
For creating a program and a source file see Discussion of Activity 1.
For the introduction of the main program,another library (#include <math.h>)
should be declared first because the computation includes complicated
computations, supported by a category (using namespace std;). In this program, the
int main cannot be used because there are other types of data that would be used
are not supported by the int main which involve decimals. Therefore, the keywords
void main () would be used. To proceed to the main program, an open curly brace
{ shall be used.
Start the main program by introducing the variables to be used. These
variables are assigned with a name that would be used consistently throughout the
program. Remember to use a variable name that describes the data it contains. As
mentioned earlier, there are other types of data that will be used. There is this data
called int (integer) which can only accommodate whole numbers. This will then be
used for the downpayment. Another data called double shall be used. It is a data
that can accommodate those numbers with decimal places. This will then be used to
contain the other variabes which involve numbers like the breakdowns of the
downpayment. The last type of data used is the char (character). This data
contains the information required as input in the program. It usually requires a
maximum number of characters to be used, and this is contained inside a square
bracket (e.g. [20]) , this means that the variable is only limited to accepting input of
up to 25 characters. If no square bracket used, the variable can only accept one
character. It includes the last name, first name and the middle name.
After the variable names are declared, they are now ready to be assigned
according to the inputs to be entered. First, use an output (cout) asking for the
personal information of the student. Then assign a variable name to contain the
inputs to be entered by the user by using cin. However, using cin alone cannot
recognize those inputs with two or more words or those that contain space in
between characters. Thats why cin.getline is used, and also shall include inside a
parenthesis the variable name and the number of characters it can contain (e.g.
cin.getline(name1,20)).
After the personal information are entered, proceed to the program which
accepts the downpayment of the student, then proceed to making formula for the
computation of the breakdown which includes the tuition fee(40%), different
miscellaneous fees like laboratory fee(25%), internet fee(10%), Library(15%), and
test papers(10%).
After the formula, is the displaying of the answer in the form of cout like what
is in the program.
In this program, since void main is used, there is no need to end the main
program with return 0. Proceed immediately in using the closed curly brace }
unindented.
Note that the design of the program depends on your choice. It may include
spaces and lines as separation.
Start the program(See Discussion of Activity 1).

Das könnte Ihnen auch gefallen