Lemoa
Lemoa
CONTENT
DECLARATION………….…………………………………………………………………. I
Acknowledgement………………………………………………………………………….. II
Question……………………………………………………………………………….1
Pseudocode…………………………………………………………………………… 2
Flowchart……………………………………………………………………………... 3
Source Code…………………………………………………………………………...4
Question……………………………………………………………………………….7
Pseudocode…………………………………………………………………………....8
Flowchart……………………………………………………………………………..10
Source Code…………………………………………………………………………..11
Question……………………………………………………………………………...15
Pseudocode…………………………………………………………………………...16
Flowchart……………………………………………………………………………..18
Source Code……………………………………………………...…………………..26
Input and Output……………………………………………………………………...23
Task B4: Arrays….…………………….…………………………………………………... 24
Question……………………………………………………………………………...24
Pseudocode…………………………………………………………………………...26
Flowchart……………………………………………………………………………..28
Source Code……………………………………………………...…………………..30
Question……………………………………………………………………………...36
Pseudocode…………………………………………………………………………...38
Flowchart……………………………………………………………………………..41
Source Code……………………………………………………...…………………. 43
Reflection…………………………………………………………………………………… 49
1
Pseudocode
Step 1:
Step 2:
1) Start
4) Switch(itemcode)
4.1) case 1
4.1.1) price=25.00
4.2) case 2
4.2.1) price=5.50
4.3) case 3
4.3.1) price=200.00
4.4) case 4
4.4.1) price=150.00
4.5) case 5
4.5.1) price=80.00
4.6) case 6
4.6.1) price=30.00
4.7) Default
5) total=(float)quantity*price
6) print total
7) End
2
Flowchart
3
Source code
switch(itemcode){
case 1:
price=25.00;
break;
case 2:
price=5.50;
break;
case 3:
4
price=200.00;
break;
case 4:
price=150.00;
break;
case 5:
price=80.00;
break;
case 6:
price=30.00;
break;
default:
printf("Invalid Item Code");
}
printf("Enter quantity:");
scanf("%d",&quantity);
total=(float)quantity*price;
printf("Total price:RM%.2f",total);
5
Input and Output
6
7
Pseudocode
Step 1:
Output: Display menu, total price, item price, item code, quantity, customer number
Formula: total+(float)quantity*price.
Step 2:
1) Start
3) Start looping
3.2.1) price=25.00
3.2.2) case 2
3.2.1) price=5.50
3.2.3) case 3
3.2.1) price=200.00
3.2.4) case 4
3.2.1) price=150.00
3.2.5) case 5
3.2.1) price=80.00
3.2.6) case 6
3.2.1) price=30.00
3.2.7) Default
8
4) End loop if any==’N’ or any==’n’
8) total+= quantity*price
9) print total
10) End
9
Flowchart
10
Source code
//ic:051205-10-2167
//index number:SW4110/1057
#include <stdio.h>
int main()
printf("\n-----------------------------------------------------");
printf("\nItem Code\t\tDescription\t\tPrice");
printf("\n 1\t\t\tTyre alignment\t\t25.00");
printf("\n 2\t\t\tTyre balancing\t\t5.50");
int itemcode,quantity,i=0;
do{
i++;
printf("\nNO.%d",i);
printf("\nEnter item code :");
11
switch(itemcode){
case 1:
price=25.00;
break;
case 2:
price=5.50;
break;
case 3:
price=200.00;
break;
case 4:
price=150.00;
break;
case 5:
price=80.00;
break;
case 6:
price=30.00;
break;
default:
break;
12
}while(x=='y'||x=='Y');
printf("\n-------------------------------------------------------------------------");
printf("\nTotal price:RM%.2f",total);
printf("\n-------------------------------------------------------------------------");//total price
for all repitition
return 0;
13
Input and Output
14
15
Pseudocode
Step 1:
Output: Display menu, total price, item price, item code, quantity, customer number
Formula: price=calculateItemPrice(itemcode, quantity)
total+=price
Step 2:
Main:
1) Start
5) Start looping
5.1) i++
5.5) total+=price
5.6) Enter any
7) Print total
8) End
Function:
1) Start
2) float customerinfo(int itemcode, int quantity)
3) Switch(itemcode)
3.1) case 1
3.1.1) price=25.00
16
3.2) case 2
3.2.1) price=5.50
3.3) case 3
3.3.1) price=200.00
3.4) case 4
3.4.1) price=150.00
3.5) case 5
3.5.1) price=80.00
3.6) case 6
5.2.6.1) price=30.00
3.7) Default
3.7.1) print “Invalid Item Code
4) return price*quantity
17
Flowchart
Main:
18
Function:
19
Source Code
//ic:051205-10-2167
//index number:SW4110/1057
#include <stdio.h>
printf("\n-----------------------------------------------------");
printf("\nItem Code\t\tDescription\t\tPrice");
printf("\n 1\t\t\tTyre alignment\t\t25.00");
int itemcode,quantity,i=0;
float price, total, itemprice;
do{
i++;
printf("\nNO.%d",i);
20
printf("\nAny more item(Y/N):");
scanf(" %c",&x);
printf("\n-------------------------------------------------------------------------");
printf("\nTotal price:RM%.2f",total);
float initial,itemprice,price;
switch(itemcode){
case 1:
price=25.00;
break;
case 2:
price=5.50;
break;
case 3:
price=200.00;
break;
case 4:
price=150.00;
break;
21
case 5:
price=80.00;
break;
case 6:
price=30.00;
break;
default:
printf("Enter quantity:");
scanf("%d",&quantity);//enter quantity
itemprice=quantity*price;//define itemprice
return quantity*price;//return value
22
Input and Output
23
24
25
Pseudocode
Step 1:
Output: Display menu, total price, item price, item code, quantity, customer number,
customertotalprice[i]
customertotalprice[i]+=price
Step 2:
Main:
1) Start
2) Display variables for item code, description and price
3) float calculateItemPrice(int,int)
5) Declare customertotalprice[i]
6.1) j=0
6.2.1) j++
6.2.2) Print customer no
6.2.6) customertotalprice[i]+=price
26
9) Print total
10) END
Function:
1) Start
2) float calculateItemPrice(int itemcode, int quantity)
3) Switch(itemcode)
3.1) case 1
3.1.1) price=25.00
3.2) case 2
3.2.1) price=5.50
3.3) case 3
3.3.1) price=200.00
3.4) case 4
3.4.1) price=150.00
3.5) case 5
3.5.1) price=80.00
3.6) case 6
5.2.6.1) price=30.00
3.7) Default
4) return price*quantity
27
Flowchart
Main:
price=calculateItemPrice(itemcode, quantity)
True
28
Function:
29
Source Code
//ic:051205-10-2167
#include <stdio.h>
int itemcode,quantity,i,j=0;
float price,total,initial;
char any;// define integers
float customertotalprice[3];
printf("\n-----------------------------------------------------");
printf("\nItem Code\t\tDescription\t\tPrice");
for(i=0;i<3;i++)//for loop
j++;
printf("\nNo.%d",j);
30
price= calculateItemPrice(itemcode, quantity);//function call
customertotalprice[i]+=price;
printf("---------------------------------------------------");
printf("---------------------------------------------------\n");//printing
of total 1 customer price
}
printf("---------------------------------------------------");
printf("\nCharge Summary\n");
printf("---------------------------------------------------");
printf("\nCustomer 1 : RM%.2f",customertotalprice[0]);
printf("\nCustomer 2 : RM%.2f",customertotalprice[1]);
total=customertotalprice[0]+customertotalprice[1]+customertotalprice[2];
printf("\n\n---------------------------------------------------");
{
float price,initial;
31
int i;
float customertotalprice[3];
scanf("%d",&itemcode);//define itemcode
switch(itemcode)
case 1:
price=25.00;
break;
case 2:
price=5.50;
break;
case 3:
price=200.00;
break;
case 4:
price=150.00;
break;
case 5:
price=80.00;
break;
case 6:
price=30.00;
break;
default:
printf("invalid item code");
32
printf("Enter quantity : ");
scanf("%d",&quantity);//define quantity
33
Input and Output
34
35
RESTRICTED STPM
2024
ICT COURSEWORK
Assignment B5: Structures (Duration: 2 periods)
Based on Assignment B4, construct an algorithm that reads and stores three customer records
using the following structure.
struct Customer{
char custName[20];
char custID[4];
float price;
};
typedef struct Customer buyer;
buyer itemList[recordNo];
The algorithm will display the customer name, customer ID and the total price for each
customer and grand total of item price.
Write a program C based on the algorithm above. The program code in Assignment B4 can be
used.
36
37
Pseudocode
Step 1:
Output: Display menu, total price, item price, item code, quantity, customer number,
itemlist[i].price, total[i]
Step 2:
Main:
1)Start
2)Define recordNo as 3
3) float calculateItemPrice(int,int)
4) struct customer
4.1) char custName[20]
7.1) j=0
7.3) j++
38
7.5.3) print price
7.5.4) total[i]+=itemlist[i].price
8) i=0
9.3) i++
10) End loop
11) Print grand total
12) End
Function:
1) Start
2) float calculateItemPrice (int itemcode, int quantity)
3) Switch(itemcode)
3.1) case 1
3.1.1) price=25.00
3.2) case 2
3.2.1) price=5.50
3.3) case 3
3.3.1) price=200.00
3.4) case 4
3.4.1) price=150.00
3.5) case 5
3.5.1) price=80.00
3.6) case 6
39
5.2.6.1) price=30.00
3.7) Default
4) return price*quantity
40
Flowchart:
Itemlist[i].price=calculateItemPrice(itemcode, quantity)
41
Function:
42
Source code
//ic:051205-10-2167
//index number:SW4110/1057
#include <stdio.h>
#define recordNo 3
struct customer{
char custName[20];
char custID[4];
float price;
};
int main()
printf("\nItem Code\t\tDescription\t\tPrice");
float total[recordNo],grandtotal;
43
int itemcode, quantity,j,i;
char any;
for(i=0;i<recordNo;i++){
j=0;
printf("\n\nCustomer %d",i+1);
printf("\n-----------\n");
scanf("%s",&itemlist[i].custName);
printf("Customer ID : ");
scanf(" %s",&itemlist[i].custID);
do{
j++;
printf("\n\nNo.%d",j);
total[i]+=itemlist[i].price;
printf("\nAny more item(Y/N) : ");
scanf(" %c",&any);
}while(any=='Y'||any=='y');
printf("\n-----------------------------------------------------------------
----------");
printf("\n-----------------------------------------------------------------
----------");
}
}
44
printf("\n\n---------------------------------------------------------------------------");
printf("\nCharge Summary");
printf("\n---------------------------------------------------------------------------");
printf("\n%s\t\t\t%s\t\t
RM%.2f",itemlist[i].custName,itemlist[i].custID,total[i]);
}
printf("\n---------------------------------------------------------------------------");
printf("\n---------------------------------------------------------------------------");
{
float price,initial;
int i;
float total[i];
scanf("%d",&itemcode);//define itemcode
switch(itemcode)
{
case 1:
itemlist[i].price=25.00;
break;
case 2:
itemlist[i].price=5.50;
break;
case 3:
45
itemlist[i].price=200.00;
break;
case 4:
itemlist[i].price=150.00;
break;
case 5:
itemlist[i].price=80.00;
break;
case 6:
itemlist[i].price=30.00;
break;
default:
printf("invalid item code");
scanf("%d",&quantity);//define quantity
46
Input and output
47
48
Reflexion
In this coursework I have learned a lot about c programming such as looping, structure, array
and many more. Even I have faced many challenges doing this coursework when developing
the code but I still managed to overcome the errors and problems. Besides that I also learnt a
lot about pseudocode and flowchart knowledge in this coursework. I am gratitude that I have
wonderful teachers and friends to help me along this journey and letting me develop these
programs smoothly.
49