0% found this document useful (0 votes)
34 views12 pages

Laboratory Exercises #3 - IF

1. The document is a laboratory exercise assignment from the College of Engineering and Architecture at Don Honorio Ventura State University. 2. It contains 3 questions to create C++ programs - a program to check if a rectangle is a square, a program to calculate payment details based on payment method, and a program to calculate a student's grade details. 3. The student is expected to write the C++ code for each program, include their output, and submit the completed assignment.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views12 pages

Laboratory Exercises #3 - IF

1. The document is a laboratory exercise assignment from the College of Engineering and Architecture at Don Honorio Ventura State University. 2. It contains 3 questions to create C++ programs - a program to check if a rectangle is a square, a program to calculate payment details based on payment method, and a program to calculate a student's grade details. 3. The student is expected to write the C++ code for each program, include their output, and submit the completed assignment.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Republic of the Philippines

Don Honorio Ventura State University


Villa de Bacolor, Pampanga
College of Engineering and Architecture

CFP 112 - COMPUTER PROGRAMMING AND FUNDAMENTALS


Laboratory Exercises #3
Name: Manansala, Charisma L. Score: ____________
Course/Yr/Sec: BSIE 1C Date: January 06, 2022

Note: All answers (source code) must be placed after the question and your output
program must be screenshot.

1. Create a C++ program that accepts values of length and breadth of a rectangle from the
user and check if it is square or not. (if length and breadth are equal it's a square).

Sample Output:
Enter length of rectangle: _5
Enter breadth of rectangle: _5
It is a square.

1 #include <iostream>
2 using namespace std;
3 int main()
4 {
5 int lrec;
6 int brec;
7
8 cout<<"Enter length of rectangle:";
9 cin>>lrec;
10 cout<<"Enter breadth of rectangle:";
11 cin>>brec;
12
13 if(lrec==brec)
14 {
15 cout<<"It is a square";
16 }
17 else
18 {
19 cout<<"It is a rectangle";
20 }
21
22 return 0;
23 }
24
2. Create a C++ program that accepts input of product name, quantity, price, amount paid.
Compute for the Total(price * quantity) then determine if the mode of payment is Cash or
Installment. Compute for the Amount Due based on the mode of payment as well as
Change.

Sample Output:
Product Name: _
Price: _
Quantity: _
Total: * P*Q
Mode of Payment(C-Cash/R=Credit): _
Amount Due: * Cash🡪 AD=total
Amount Paid: _
Change: * Cash🡪 C=AP – AD
Number of months: _
Amount Due: * cRedit🡪 AD=total + total(nom * 0.10)
Monthly Bill: * cRedit🡪MB=AD / nom
Amount Paid: _
Change: * cRedit🡪 C=AP – MB
Remaining Balance: * cRedit🡪RB=AP – AD
1 #include <iostream>
2 using namespace std;
3 int main(){
4 char pn[20], mp;
5 double p, q, total, cash, nom;
6 double mb, ad, ap, rb;
7 int change;
8 cout<<"Product name: ";
9 cin>>pn;
10 cout<<"Price: ";
11 cin>>p;
12 cout<<"Quantity: ";
13 cin>>q;
14
15 total = p* q;
16
17 cout<<"Total: "<<total<<endl;
18 cout<<"Mode of Payment (C-Cash/R-Credit): ";
19 cin>>mp;
20 if(mp=='c' || mp == 'C'){
21
22 ad = total;
23 cout<<"Amount Due: "<< ad <<endl;
24 cout<<"Amount Paid: ";
25 cin>>cash;
26 change = cash - total;
27 cout<<endl;
28
29 cout<<"Change: "<<change;
30
31
32 }
33 else if(mp =='r' || mp =='R'){
34
35 cout<<"Number of months: ";
36 cin>>nom;
37 cout<<endl;
38
39 ad = total+total*nom*0.10;
40 cout<<"Amount Due: "<< ad <<endl;
41 mb = ad/nom;
42 cout<<"Monthly Bill: "<<mb<<endl;
43 cout<<"Amount Paid: ";
44 cin>>ap;
45 cout<<endl;
46
47 change = ap-mb;
48 cout<<"Change: "<<change<<endl;
49 rb = ap - ad;
50 cout<<"Remaining Balance: "<<rb;
51
52 }
53 else{
54 cout<<"Invalid Payment Method";
55 }
56 }

1 #include <iostream>
2 using namespace std;
3 int main(){
4 char pn[20], mp;
5 double p, q, total, cash, nom;
6 double mb, ad, ap, rb;
7 int change;
8 cout<<"Product name: ";
9 cin>>pn;
10 cout<<"Price: ";
11 cin>>p;
12 cout<<"Quantity: ";
13 cin>>q;
14
15 total = p* q;
16
17 cout<<"Total: "<<total<<endl;
18 cout<<"Mode of Payment (C-Cash/R-Credit): ";
19 cin>>mp;
20 if(mp=='c' || mp == 'C'){
21
22 ad = total;
23 cout<<"Amount Due: "<< ad <<endl;
24 cout<<"Amount Paid: ";
25 cin>>cash;
26 change = cash - total;
27 cout<<endl;
28
29 cout<<"Change: "<<change;
30
31
32 }
33 else if(mp =='r' || mp =='R'){
34
35 cout<<"Number of months: ";
36 cin>>nom;
37 cout<<endl;
38
39 ad = total+total*nom*0.10;
40 cout<<"Amount Due: "<< ad <<endl;
41 mb = ad/nom;
42 cout<<"Monthly Bill: "<<mb<<endl;
43 cout<<"Amount Paid: ";
44 cin>>ap;
45 cout<<endl;
46
47 change = ap-mb;
48 cout<<"Change: "<<change<<endl;
49 rb = ap - ad;
50 cout<<"Remaining Balance: "<<rb;
51
52 }
53 else{
54 cout<<"Invalid Payment Method";
55 }
56 }
3. Create a C++ program that will accept input of student name, section, subject, midterm
and final grade. Compute for the sem grade then display the grade equivalent,
classification and remarks.

Student Name:_ char sn[25];/string sn;


Section:_ char sec[10];/string sec;
Subject:_ char subj[10];/string subj;
Midterm Grade:_ int mg;
Final Grade:_ int fg;
Sem Grade:* int sg; sg=(mg+fg)/2;
Equivalent:* float eq;
Classification:* string classi;
Remarks:* string rem; if(sg>=75) , if(sg<=74), if(mg==0 || fg==0)

1 #include <iostream>
2 using namespace std;
3 int main()
4{
5 string sn;
6 string sec;
7 string subj;
8 int mg;
9 int fg;
10 int sg;
11 float eq;
12 string classi;
13 string rem;
14
15 cout<<"Student Name:";
16 getline(cin,sn);
17 cout<<"Section:";
18 getline(cin,sec);
19 cout<<"Subject:";
20 getline(cin,subj);
21 cout<<"Midterm Grade:";
22 cin>>mg;
23 cout<<"Final Grade:";
24 cin>>fg;
25 sg=(mg+fg)/2;
26 cout<<"Sem Grade:"<<sg;
27 if(sg==100)
28 {
29 eq=1.00;
30 }
31 else if(sg==99)
32 {
33 eq=1.05;
34 }
35 else if(sg==98)
36 {
37 eq=1.10;
38 }
39 else if(sg==97)
40 {
41 eq=1.15;
42 }
43 else if(sg==96)
44 {
45 eq=1.20;
46 }
47 else if(sg==95)
48 {
49 eq=1.25;
50 }
51 else if(sg==94)
52 {
53 eq=1.30;
54 }
55 else if(sg==93)
56 {
57 eq=1.35;
58}
59 else if(sg==92)
60 {
61 eq=1.40;
62 }
63 else if(sg==91)
64 {
65 eq=1.45;
66 }
67 else if(sg==90)
68 {
69 eq=1.50;
70 }
71 else if(sg==89)
72 {
73 eq=1.60;
74 }
75 else if(sg==88)
76 {
77 eq=1.70;
78 }
79 else if(sg==87)
80 {
81 eq=1.80;
82 }
83 else if(sg==86)
84 {
85 eq=1.90;
86 }
87 else if(sg==85)
88 {
89 eq=2.00;
90 }
91 else if(sg==84)
92 {
93 eq=2.10;
94}
95 else if(sg==83)
96 {
97 eq=2.20;
98 }
99 else if(sg==82)
100{
101 eq=2.30;
102 }
103 else if(sg==81)
104 {
105 eq=2.40;
106 }
107 else if(sg==80)
108 {
109 eq=2.50;
110 }
111 else if(sg==79)
112 {
113 eq=2.60;
114 }
115 else if(sg==78)
116 {
117 eq=2.70;
118 }
119 else if(sg==77)
120 {
121 eq=2.80;
122 }
123 else if(sg==76)
124 {
125 eq=2.90;
126 }
127 else if(sg==75)
128 {
129 eq=3.00;
130 }
131 else if(sg<=74)
132 {
133 eq=5.00;
134 }
135 cout<<"\n\nEquivalent:"<<eq;
136 if(sg>=99 && sg<=100)
137 {
138 classi="Excellent";
139 }
140 else if(sg>=93 && sg<=98)
141 {
142 classi="Superior";
143 }
144 else if(sg>=85 && sg<=92)
145 {
146 classi="Very Good";
147 }
148 else if(sg>=80 && sg<=84)
149 {
150 classi="Good";
151 }
152 else if(sg>=76 && sg<=79)
153 {
154 classi="Fair";
155}
156 else if(sg==75)
157 {
158 classi="Pass";
159 }
160 else if(sg<=74)
161 {
162 classi="Fail";
163 }
164 cout<<"\nClassification:"<<classi;
165 if(sg>=75)
166 {
167 rem="PASSED";
168 }
169 if(sg<=74)
170 {
171 rem="FAILED";
172 }
173 cout<<"\nRemarks:"<<rem;
174
175 return 0;
176 }

You might also like