ZQMS-ARC-REC-002
ASSIGNMENT COVER
REGION: HARARE SEMESTER: 1 YEAR: 1
PROGRAMME: BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY HONOURS
INTAK E: 2
FULL NAME OF STUDEN T: PRINCE NYIKADZINO
PIN: P2285746Y
EMAIL ADDRESS: princenyikadzino118@[Link]
CONTACT TELEPHONE/CELL: +263774640728 ID. NO: 63-2022886 X27
COURSE NAME: COMPUTER PROGRAMMING COURSE CODE: BSIT131
ASSIGNMENT NO. e.g. 1 or 2: 2(TWO)
STUDENT’S SIGNATURE:
DUE DATE: 30 SEPTEMBER 12:00AM SUBMISSION DATE: 23 SEPTEMBER
ASSIGNMENT TITLE:
Instructions
Marks will be awarded for good presentation and thoroughness in your approach.
NO marks will be awarded for the entire assignment if any part of it is found to be copied directly
from printed materials or from another student.
Complete this cover and attach it to your assignment. Insert your scanned signature.
Studentdeclaration
I declare that:
I understand what is meant by plagiarism
The implications of plagiarism have been explained to me by the institution
This assignment is all my own work and I have acknowledged any use of the published or
unpublished works of oth er people.
MARK ER’S COMMEN TS:
OVERALL MARK: MARK ER’S NAME:
MARK ER’S SIGNATURE: DATE:
Question 1
Write a C program to make a simple calculator to add, subtract, multiply and divide
two numbers using switch statement.
Your program should implement four functions add(),subtract(), divide() and
multiply()
This program first takes two integer operands and an arithmetic operator as input
from user. The operator is stored in a character variable 'operator'. Only addition,
subtraction, multiplication and division- (+,
, * and /) operators are allowed, for any
other operator it prints error message on screen. Hint: You may use a switch case
statement to perform a particular arithmetic operation based on the 'operator'
variable. If none of the operator matches with the input operator then it prints an
error mess age on screen. [25 Marks]
#include <stdio.h>
int main()
{
char op;
double first, second;
printf("Enter an operator (+, -, *, /): ");
scanf("%c", &op);
printf("Enter two operands: ");
scanf("%lf %lf", &first, &second);
switch (op)
{
case '+':
printf("%.1lf + %.1lf = %.1lf", first, second, first + second);
break;
case '-':
printf("%.1lf - %.1lf = %.1lf", first, second, first - second);
break;
case '*':
printf("%.1lf * %.1lf = %.1lf", first, second, first * second);
break;
case '/':
printf("%.1lf / %.1lf = %.1lf", first, second, first / second);
break;
// operator doesn't match any case constant
default:
printf("Error! operator is not correct");
}
return 0;
}
OUTPUT
Question 2
Write a C program to find the minimum or the smallest element in an array [15 Marks]
#include<stdio.h>
int main()
{
int a[1000],i,size,min=0;
printf("Enter the size of an Array : ");
scanf("%d",&size);
printf("Enter elements in array : \n");
for(i=0; i<size ;i++)
{
scanf("%d", &a[i]);
}
min=a[0];
for(i=1; i<size; i++)
{
if(min>a[i])
min=a[i];
}
printf("minimum value in array is : %d",min);
return 0;
}
OUTPUT
Question 3
Write a C program to check if a string is a palindrome or not. A palindrome string is one the
reads the same backwards as well as forward e.g. DAD [10 Marks]
#include<stdio.h>
#include <string.h>
int main()
{
char a[100], b[100];
printf("Enter the string:");
gets(a);
strcpy(b, a);
strrev(b);
if (strcmp(a, b) == 0)
printf("The string is a palindrome\n");
else
printf("The string is not t a palindrome\n");
return 0;
}
OUTPUT FOR PALINDROME
OUTPUT: NOT PALINDROME
Question 4
Write a C program that simulates how Ecocash or One Money .works
[50 Marks]
#include<stdio.h>
int main()
{
int sel,pin,l,etym,services,conf,data;
char quit = '#';
char back ='*';
printf("Enter your ecocash pin\n");
scanf("%d", &pin);
printf("welcome to ecocash Main menu:\nChoose from the menu below\n");
menu:
printf("1. Balance\n");
printf("2. Buy airtime\n");
printf("3. Buy data\n");
printf("4. Banking\n");
scanf("%d",&sel);
switch(sel)
{
case (1):
printf("Your balance is .... 400000RTGS \n");
printf("Press * to go to main menu\n");
scanf("%c", &back);
if(back == '*')
{
goto menu;
}
break;
case (2):
printf("Please Choose which one you want\n");
printf("1. 2min 30zwl\n");
printf("2. 3min 40zwl\n");
printf("3. 10min 50zwl \n");
printf("4. 50min 70zwl\n");
scanf("%d",&etym);
switch(etym)
{
case (1):
printf("You are about to purchase 2min talktime for 30zwl. \n Press 1 to confirm: ");
scanf("%d",&conf);
switch (conf)
{
case(1):
printf("Thank you for your purchase.");
break;
default:
printf("Error Try again.");
}
break;
case (2):
printf("You are about to purchase 3min talktime for 40zwl. \n Press 1 to confirm: ");
scanf("%d",&conf);
switch (conf)
{
case(1):
printf("Thank you for your purchase.");
break;
default:
printf("Error Try again.");
}
break;
case (3):
printf("You are about to purchase 10min talktime for 50zwl. \n Press 1 to confirm: ");
scanf("%d",&conf);
switch (conf)
{
case(1):
printf("Thank you for your purchase.");
break;
default:
printf("Error Try again.");
}
case (4):
printf("You are about to purchase 50min talktime for 70zwl. \n Press 1 to confirm: ");
scanf("%d",&conf);
switch (conf)
{
case(1):
printf("Thank you for your purchase.");
break;
default:
printf("Error Try again.");
}
default:
printf("Error:::press * to go back or # to exit. ");
scanf("%d",&quit);
}
break;
case (3):
printf("Please Choose Data package ");
printf("1. 200MB 730zwl\n");
printf("2. 335MB 890zwl\n");
printf("3. 1024MB 1050zwl \n");
printf("4. 1500MB 3570zwl\n");
scanf("%d",&data);
switch(data)
{
case (1):
printf("You are about to purchase 200MB for 730zwl. \n Press 1 to confirm: ");
scanf("%d",&conf);
switch (conf)
{
case(1):
printf("Thank you for your purchase.");
break;
default:
printf("Error Try again.");
}
break;
case (2):
printf("You are about to purchase 335MB for 1050zwl. \n Press 1 to confirm: ");
scanf("%d",&conf);
switch (conf)
{
case(1):
printf("Thank you for your purchase.");
break;
default:
printf("Error Try again.");
}
break;
case (3):
printf("You are about to purchase 1024MB 730zwl. \n Press 1 to confirm: ");
scanf("%d",&conf);
switch (conf)
{
case(1):
printf("Thank you for your purchase.");
break;
default:
printf("Error Try again.");
}
case (4):
printf("You are about to purchase 1500MB for 3570zwl. \n Press 1 to confirm: ");
scanf("%d",&conf);
switch (conf)
{
case(1):
printf("Thank you for your purchase.");
break;
default:
printf("Error Try again.");
}
default:
printf("Error:::press * to go back or # to exit. ");
scanf("%d",&quit);
}
case (4):
printf("Welcome to banking services.\nSelect any options below\n");
printf("1. Bank to ecocash\n");
scanf("%d",&services);
switch(services)
{
case 1:
printf("select account\n");
printf("1. rtgs account\n");
printf("2. nostro account\n");
int acc;
scanf("%d", &acc);
switch(acc)
{
case 1:
printf("Amount: ");
int amnt;
scanf("%d",&amnt);
printf ("You are about to transfer %drtgs to your ecocash account \n. Press 1 to
confirm:\n",amnt);
scanf("%d",&conf);
switch (conf)
{
case(1):
printf("Your transfer was successful. \n");
break;
case 2:
printf("Amount");
scanf("%d",&amnt);
printf ("You are about to transfer %dusd to your ecocash account \n. Press 1 to
confirm:\n",amnt);
scanf("%d",&conf);
switch (conf)
{
case(1):
printf("Your transfer was successful.");
break;
}
}
}
}
}
return 0;
}
OUTPUT
Total [100 Marks]