SlideShare a Scribd company logo
MIDTERM EXAM FOR
PROGRAMMING 2
Batch 3
Design a program that will accept
a maximum of 5 customers.
If your choice is 1: -------------- void ADD()
First name:
• printf("FIRST NAME:"); scanf("%s",&name[x]); getchar();
Name of item:
• printf(“ITEM NAME:"); scanf("%s",&item[x]); getchar();
Price:
• printf("PRICE:"); scanf("%d",&price[x]);
Quantity:
• printf("QUANTITY:"); scanf("%d",&qty[x]);
• Clear the previous display ----------------- clrscr();
• Accept the following:
Then compute for total amount,
where total amount is:
price * quantity.
• totalAmt[x]=price[x]*qty[x];
• If total amount is lesser than or equal to 1000, give 5% discount.
Compute for total discounted amount, where:
Total Discounted Amount is Total Amount – Discounted Amount.
Display Total Discounted Amount.
• Else if total amount is greater than 1000, but less than or equal to 2000,
give 10% discount. Compute for total discounted amount, where:
Total Discounted Amount is Total Amount – Discounted Amount.
Display Total Discounted Amount.
• Else if total amount is greater than 2000, but less than 5000, give 15%
discount. Compute for total discounted amount, where:
Total Discounted Amount is Total Amount – Discounted Amount.
Display Total Discounted Amount.
• Else give 20% discount. Compute for total discounted amount, where:
Total Discounted Amount is Total Amount – Discounted Amount.
Display Total Discounted Amount
If (totalAmt[x]<=1000)
{ dc[x] = totalAmt[x] * 0.05;
disc[x] = totalAmt[x] - dc[x];
printf ("TOTAL DISCOUNTED AMOUNT: %f", disc[x]); }
else if (totalAmt[x]>1000 && totalAmt[x]<=2000)
{ dc[x] = totalAmt[x] * 0.10;
disc[x] = totalAmt[x] - dc[x];
printf ("TOTAL DISCOUNTED AMOUNT: %f", disc[x]); }
else if (totalAmt[x]>2000&&totalAmt[x]<5000)
{ dc[x] = totalAmt[x] * 0.15;
disc[x] = totalAmt[x] - dc[x];
printf ("TOTAL DISCOUNTED AMOUNT: %f",disc[x]); }
else
{ dc[x] = totalAmt[x] * 0.20;
disc[x] = totalAmt[x] - dc[x];
printf ("TOTAL DISCOUNTED AMOUNT: %f",disc[x]); }
After all the inputs, ask “DO YOU
WANT TO GO TO MAIN MENU? 1
for YES | 2 for NO”…
• If 1 go to Main Menu or Main Display
 if(opt==1) { MAIN(); }
• If 2 Exit
 else { exit(0);}
If your choice is 2: -------------- void EDIT()
• Clear the previous display ----------------- clrscr();
• Display “NO RECORDS AVAILABLE” if no information of
entrepreneurs that were added.
• Else, display all information of customer.
• If you wish to edit the information of customer, display “DO
YOU WANT TO EDIT INFORMATION?
1 for YES | 2 for NO”
• If you entered 1, accept a number from list you want to edit.
Display EDIT MENU.
• Choose what field of information you would like to edit.
• If your choice is 1, then EDIT the FIRST NAME only
• If your choice is 2, EDIT the ITEM NAME
• If your choice is 3, EDIT the QUANTITY
• If your choice is 4, EDIT the PRICE
• After all the inputs, ask “DO YOU WANT TO GO TO MAIN
MENU? 1 for YES | 2 for NO…
• If 1 go to Main Menu or Main Display
 if(opt==1) { MAIN(); }
• If 2 Exit
 else { exit(0);}
EDIT INFORMATION
FIRST NAME ITEM QUANTITY PRICE TOTAL AMOUNT TOTAL DISCOUNTED AMOUNT
1. Khatt bag 2 950 19,000 18,620
2. Jenny pen 5 100 500 495
Do you want to edit information? 1 for YES | 2 for NO: 1
Enter a number from the list: 1
Choose what field to edit:
• FIRST NAME
• NAME OF ITEM
• QUANTITY
• PRICE
ENTER YOUR CHOICE: 1
************************** EDIT CUSTOMER’S INFORMATION ************************
ENTER FIRST NAME: firstname
Do you want to go to Main Menu? 1 for YES | 2 for NO:
void EDIT()
{ clrscr();
if(x==0)
{ printf("NO RECORDS AVAILABLE!"); }
else
{ printf("ALL INFORMATION of CUSTOMER");
printf("FIRST NAME ITEM QTY PRICE AMOUNT DISCOUNTED AMT");
for (y=1; y<=x; y++)
{
printf("%d. %s %s %d %d %d %f",y, name[y],item[y],qty[y],price[y],totalAmt[y],disc[y]); }
printf("DO YOU WANT TO EDIT INFORMATION? 1 for YES | 2 for NO:");scanf("%d",&num);
if(num==1)
{ printf ("ENTER A NUMBER FROM THE LIST: "); scanf("%d",&number);
printf (“ CHOOSE WHAT FIELD TO EDIT:");
printf (“ 1. FIRST NAME");
printf (“ 2. NAME OF ITEM");
printf (“ 3. QUANTITY");
printf (“ 4. PRICE");
printf (" ENTER YOUR CHOICE: "); scanf("%d",&ch);
switch(ch)
switch(ch)
{ clrscr();
case 1: printf (“ ENTER FIRST NAME:"); scanf("%s",&name[number]); getchar();
break;
case 2: printf (“ ENTER NAME OF ITEM:"); scanf("%s",&item[number]); getchar();
break;
case 3: printf (“ ENTER QUANTITY:"); scanf("%d",&qty[number]);
break;
case 4: printf (“ ENTER PRICE:"); scanf("%d",&price[number]);
break;
}
printf("DO YOU WANT TO GO TO MAIN? 1 for YES | 2 for NO:");scanf("%d",&opt);
if(opt==1)
{ MAIN(); }
else { exit(0); }
else
{ exit(0); }
}}
If your choice is 3: -------------- void Display()
• Clear the previous display ----------------- clrscr();
• Display “NO RECORDS AVAILABLE” if no information of
entrepreneurs that were added.
• Else, display all information of customer.
• If you wish to edit the information of customer, display “DO
YOU WANT TO EDIT INFORMATION?
1 for YES | 2 for NO”
• If 1 go to Main Menu or Main Display
 if(opt==1) { MAIN(); }
• If 2 Exit
 else { exit(0);}
void Display()
{
clrscr();
printf("DISPLAY INFORMATION");
if(x==0)
{ printf (“NO RECORDS AVAILABLE!"); }
else
{
printf (“ FIRST NAME ITEM QTY PRICE AMOUNT DISCOUNTED AMT");
for (y=1; y<=x; y++)
{
printf("%d. %s %s %d %d %d %f",y, name[y],item[y],qty[y],price[y],totalAmt[y],disc[y]); }
printf(" DO YOU WANT TO GO TO MAIN? 1 for YES, 2 for EXIT: ");
scanf("%d",&opt);
if(opt==1)
{ MAIN(); }
else
{ exit(0); }
}}

More Related Content

PPTX
Array menu
PPT
StackArray stack3
PPTX
Stack using Linked List
DOCX
Data structure output 1
PPTX
Stack using Array
PDF
1D Array
PPTX
V34 numeric function-c
PPTX
Python basic Program
Array menu
StackArray stack3
Stack using Linked List
Data structure output 1
Stack using Array
1D Array
V34 numeric function-c
Python basic Program

What's hot (13)

PPTX
DS- Stack ADT
PPTX
Structured query language functions
DOCX
ADA FILE
DOCX
DataStructures notes
PDF
Visual Basic
PPTX
C Programming Language Part 4
PPTX
Sas reg multi
PDF
LET US C (5th EDITION) CHAPTER 1 ANSWERS
PDF
2 3. standard io
PDF
The Ring programming language version 1.6 book - Part 44 of 189
PDF
TI-84 graphing calculator guide
PDF
Class program and uml in c++
DS- Stack ADT
Structured query language functions
ADA FILE
DataStructures notes
Visual Basic
C Programming Language Part 4
Sas reg multi
LET US C (5th EDITION) CHAPTER 1 ANSWERS
2 3. standard io
The Ring programming language version 1.6 book - Part 44 of 189
TI-84 graphing calculator guide
Class program and uml in c++
Ad

Viewers also liked (9)

PPTX
IOS 4: Multitasking
PPT
Project presentation
PPT
Final slide presentation
PPT
GEB Final Presentation with Sound
PPTX
ระบบกระดูก
PPTX
ทุเรียน
PPTX
อินเดีย
PPTX
อเมริกาเหนือ ทรัพยากรและสิ่งแวดล้อมใหม่
PPTX
วัฒนธรรม กับ ภาษาของมนุษย์
IOS 4: Multitasking
Project presentation
Final slide presentation
GEB Final Presentation with Sound
ระบบกระดูก
ทุเรียน
อินเดีย
อเมริกาเหนือ ทรัพยากรและสิ่งแวดล้อมใหม่
วัฒนธรรม กับ ภาษาของมนุษย์
Ad

Similar to Computer Programming Code Sample (20)

PDF
C programs Set 4
PPTX
cafeteria info management system
PDF
I really need help with this Assignment Please in C programming not .pdf
DOCX
You are to write a program that computes customers bill for hisher.docx
PDF
C programming tweak needed for a specific program.This is the comp.pdf
DOCX
CS Project-Source code for shopping inventory for CBSE 12th
PDF
Im posting this again because the answer wasnt correct.Please .pdf
PDF
#include stdio.h#include stdlib.h#include string.hstruct.pdf
DOCX
c++main.cpp#include iostream#include store.h#includ.docx
PDF
cs project work on canteen managment
DOCX
computer project on shopping mall..cbse 2017-2018 project
DOC
CANTEEN MANAGEMENT SYSTEM IN C++
DOC
Shopping mall
PDF
Kirti Kumawat, BCA Third Year
PDF
Computer Investigatory Project
PDF
Reshma Kodwani , BCA Third Year
PDF
The Cube - Class XII Project
PDF
12.9 Program Online shopping cart (continued) (C++)This program e.pdf
PDF
So I already have most of the code and now I have to1. create an .pdf
DOCX
CS 2336 PROJECT 3 – Linked Inventory Management Project Due 1104 b.docx
C programs Set 4
cafeteria info management system
I really need help with this Assignment Please in C programming not .pdf
You are to write a program that computes customers bill for hisher.docx
C programming tweak needed for a specific program.This is the comp.pdf
CS Project-Source code for shopping inventory for CBSE 12th
Im posting this again because the answer wasnt correct.Please .pdf
#include stdio.h#include stdlib.h#include string.hstruct.pdf
c++main.cpp#include iostream#include store.h#includ.docx
cs project work on canteen managment
computer project on shopping mall..cbse 2017-2018 project
CANTEEN MANAGEMENT SYSTEM IN C++
Shopping mall
Kirti Kumawat, BCA Third Year
Computer Investigatory Project
Reshma Kodwani , BCA Third Year
The Cube - Class XII Project
12.9 Program Online shopping cart (continued) (C++)This program e.pdf
So I already have most of the code and now I have to1. create an .pdf
CS 2336 PROJECT 3 – Linked Inventory Management Project Due 1104 b.docx

Recently uploaded (20)

PDF
Complications of Minimal Access Surgery at WLH
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
master seminar digital applications in india
PPTX
Pharma ospi slides which help in ospi learning
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Cell Structure & Organelles in detailed.
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Computing-Curriculum for Schools in Ghana
PDF
RMMM.pdf make it easy to upload and study
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Complications of Minimal Access Surgery at WLH
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
master seminar digital applications in india
Pharma ospi slides which help in ospi learning
Final Presentation General Medicine 03-08-2024.pptx
Final Presentation General Medicine 03-08-2024.pptx
GDM (1) (1).pptx small presentation for students
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Cell Structure & Organelles in detailed.
102 student loan defaulters named and shamed – Is someone you know on the list?
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
O7-L3 Supply Chain Operations - ICLT Program
Microbial diseases, their pathogenesis and prophylaxis
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Computing-Curriculum for Schools in Ghana
RMMM.pdf make it easy to upload and study
Microbial disease of the cardiovascular and lymphatic systems
2.FourierTransform-ShortQuestionswithAnswers.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape

Computer Programming Code Sample

  • 2. Batch 3 Design a program that will accept a maximum of 5 customers.
  • 3. If your choice is 1: -------------- void ADD() First name: • printf("FIRST NAME:"); scanf("%s",&name[x]); getchar(); Name of item: • printf(“ITEM NAME:"); scanf("%s",&item[x]); getchar(); Price: • printf("PRICE:"); scanf("%d",&price[x]); Quantity: • printf("QUANTITY:"); scanf("%d",&qty[x]); • Clear the previous display ----------------- clrscr(); • Accept the following:
  • 4. Then compute for total amount, where total amount is: price * quantity. • totalAmt[x]=price[x]*qty[x];
  • 5. • If total amount is lesser than or equal to 1000, give 5% discount. Compute for total discounted amount, where: Total Discounted Amount is Total Amount – Discounted Amount. Display Total Discounted Amount. • Else if total amount is greater than 1000, but less than or equal to 2000, give 10% discount. Compute for total discounted amount, where: Total Discounted Amount is Total Amount – Discounted Amount. Display Total Discounted Amount. • Else if total amount is greater than 2000, but less than 5000, give 15% discount. Compute for total discounted amount, where: Total Discounted Amount is Total Amount – Discounted Amount. Display Total Discounted Amount. • Else give 20% discount. Compute for total discounted amount, where: Total Discounted Amount is Total Amount – Discounted Amount. Display Total Discounted Amount
  • 6. If (totalAmt[x]<=1000) { dc[x] = totalAmt[x] * 0.05; disc[x] = totalAmt[x] - dc[x]; printf ("TOTAL DISCOUNTED AMOUNT: %f", disc[x]); } else if (totalAmt[x]>1000 && totalAmt[x]<=2000) { dc[x] = totalAmt[x] * 0.10; disc[x] = totalAmt[x] - dc[x]; printf ("TOTAL DISCOUNTED AMOUNT: %f", disc[x]); } else if (totalAmt[x]>2000&&totalAmt[x]<5000) { dc[x] = totalAmt[x] * 0.15; disc[x] = totalAmt[x] - dc[x]; printf ("TOTAL DISCOUNTED AMOUNT: %f",disc[x]); } else { dc[x] = totalAmt[x] * 0.20; disc[x] = totalAmt[x] - dc[x]; printf ("TOTAL DISCOUNTED AMOUNT: %f",disc[x]); }
  • 7. After all the inputs, ask “DO YOU WANT TO GO TO MAIN MENU? 1 for YES | 2 for NO”… • If 1 go to Main Menu or Main Display  if(opt==1) { MAIN(); } • If 2 Exit  else { exit(0);}
  • 8. If your choice is 2: -------------- void EDIT() • Clear the previous display ----------------- clrscr(); • Display “NO RECORDS AVAILABLE” if no information of entrepreneurs that were added. • Else, display all information of customer. • If you wish to edit the information of customer, display “DO YOU WANT TO EDIT INFORMATION? 1 for YES | 2 for NO” • If you entered 1, accept a number from list you want to edit. Display EDIT MENU. • Choose what field of information you would like to edit.
  • 9. • If your choice is 1, then EDIT the FIRST NAME only • If your choice is 2, EDIT the ITEM NAME • If your choice is 3, EDIT the QUANTITY • If your choice is 4, EDIT the PRICE • After all the inputs, ask “DO YOU WANT TO GO TO MAIN MENU? 1 for YES | 2 for NO… • If 1 go to Main Menu or Main Display  if(opt==1) { MAIN(); } • If 2 Exit  else { exit(0);}
  • 10. EDIT INFORMATION FIRST NAME ITEM QUANTITY PRICE TOTAL AMOUNT TOTAL DISCOUNTED AMOUNT 1. Khatt bag 2 950 19,000 18,620 2. Jenny pen 5 100 500 495 Do you want to edit information? 1 for YES | 2 for NO: 1 Enter a number from the list: 1 Choose what field to edit: • FIRST NAME • NAME OF ITEM • QUANTITY • PRICE ENTER YOUR CHOICE: 1 ************************** EDIT CUSTOMER’S INFORMATION ************************ ENTER FIRST NAME: firstname Do you want to go to Main Menu? 1 for YES | 2 for NO:
  • 11. void EDIT() { clrscr(); if(x==0) { printf("NO RECORDS AVAILABLE!"); } else { printf("ALL INFORMATION of CUSTOMER"); printf("FIRST NAME ITEM QTY PRICE AMOUNT DISCOUNTED AMT"); for (y=1; y<=x; y++) { printf("%d. %s %s %d %d %d %f",y, name[y],item[y],qty[y],price[y],totalAmt[y],disc[y]); } printf("DO YOU WANT TO EDIT INFORMATION? 1 for YES | 2 for NO:");scanf("%d",&num); if(num==1) { printf ("ENTER A NUMBER FROM THE LIST: "); scanf("%d",&number); printf (“ CHOOSE WHAT FIELD TO EDIT:"); printf (“ 1. FIRST NAME"); printf (“ 2. NAME OF ITEM"); printf (“ 3. QUANTITY"); printf (“ 4. PRICE"); printf (" ENTER YOUR CHOICE: "); scanf("%d",&ch); switch(ch)
  • 12. switch(ch) { clrscr(); case 1: printf (“ ENTER FIRST NAME:"); scanf("%s",&name[number]); getchar(); break; case 2: printf (“ ENTER NAME OF ITEM:"); scanf("%s",&item[number]); getchar(); break; case 3: printf (“ ENTER QUANTITY:"); scanf("%d",&qty[number]); break; case 4: printf (“ ENTER PRICE:"); scanf("%d",&price[number]); break; } printf("DO YOU WANT TO GO TO MAIN? 1 for YES | 2 for NO:");scanf("%d",&opt); if(opt==1) { MAIN(); } else { exit(0); } else { exit(0); } }}
  • 13. If your choice is 3: -------------- void Display() • Clear the previous display ----------------- clrscr(); • Display “NO RECORDS AVAILABLE” if no information of entrepreneurs that were added. • Else, display all information of customer. • If you wish to edit the information of customer, display “DO YOU WANT TO EDIT INFORMATION? 1 for YES | 2 for NO” • If 1 go to Main Menu or Main Display  if(opt==1) { MAIN(); } • If 2 Exit  else { exit(0);}
  • 14. void Display() { clrscr(); printf("DISPLAY INFORMATION"); if(x==0) { printf (“NO RECORDS AVAILABLE!"); } else { printf (“ FIRST NAME ITEM QTY PRICE AMOUNT DISCOUNTED AMT"); for (y=1; y<=x; y++) { printf("%d. %s %s %d %d %d %f",y, name[y],item[y],qty[y],price[y],totalAmt[y],disc[y]); } printf(" DO YOU WANT TO GO TO MAIN? 1 for YES, 2 for EXIT: "); scanf("%d",&opt); if(opt==1) { MAIN(); } else { exit(0); } }}