Professional Documents
Culture Documents
SOLUTION : 1
#include <stdio.h>
int main(){
int n=9;//variable 'n' denotes the number of movies
//array mov_name contains the name of movies which needs to be rated and
*mov_name is the pointer of that array
char *mov_name[9]={"Belfast","CODA","Don't Look Up","Drive My
Car","Dune","King Richard","Licorice Pizza",
"Nightmare Alley","The Power of the Dog"};
float mov_rate[n];//array mov_rate contains the rating of the movie and its data
type will be float as rating can be a decimal value as well.
if(p[j]>p[j+1])
{temp_rate=p[j];
p[j]=p[j+1];
p[j+1]=temp_rate;//swapping the rates
temp_mov=mov_name[j];
mov_name[j]=mov_name[j+1];
mov_name[j+1]= temp_mov;//swapping the movie names
}
}
}
printf("\nIn descending order, the ratings are :\n");
j=1;
for(i=n-1;i>=0;i--){//This loop is printing the ratings in descending order
printf("%d %s\nRate:%.2f\n\n",j++,mov_name[i],p[i]);
}
return 0;
}
//For this program, I first put the movie titles in a character type array (i.e- string)
and then the rating in a floating type array. After that, I took the rating of movies
as input from the user and used the bubble sort algorithm to sort the ratings in
ascending order, swapping the movie titles in the process. Afterwards, I used a 'for'
loop to print the ratings in descending order because the last digit of my ID is odd.
Solution 2
Code:
#include<stdio.h>
#include<stdlib.h>
char c_name[20];//'c_name' denotes the customer name and it will be a global variable as it
needs to be accessed by almost every function
int c_number;//'c_number' denotes the customer number and it will be a global variable as it
needs to be accessed by almost every function
float bill;//bill is declared as a global variable as it needs to be updated again and again.
void c_data();//declaring the customer data function here as this function needs access every
once in a while by other functions.
void Main_Menu();//declaring the Main_Menu function here as this function is required
frequently by other functions.
int replace=0; //'replace' is a global variable which I have initialized as 0 to indicate that the
customer does not want to replace his meter.
void bill_synopsis()//this function gives the summary of the bill
{
if (replace==1){
bill=bill+2000;//here 2000 is the meter replacement charge
}
printf("\nName: %s\nNumber: %d\nBill: %.2f\nThank you!!\n\n",c_name,c_number,bill);
Main_Menu();//again calling the Main menu function
}
void Residential()//function of Residential category
{
float unit;
printf("Enter the units consumed :");
scanf("%f",&unit);
int phase;
printf("1.1-Phase\n 2.3-Phase\nEnter choice:");
scanf("%d",&phase);
if(phase==1){
phase=10;
}
else{
phase=30;
}
if(unit<=50){
bill= bill+(unit*3.33);
}
if(unit>600){
bill=bill+((unit-600)*9.98);
unit=600;
}
if(unit>400){
bill=bill+((unit-400)*8.70);
unit=400;
}
if(unit>300){
bill=bill+((unit-300)*5.63);
unit=300;
}
if(unit>200){
bill=bill+((unit-200)*5.36);
unit=200;
}
if(unit>75){
bill=bill+((unit-75)*5.14);
unit=75;
}
if(unit>0){
bill=bill+(unit*3.80);
}
bill=bill+50+phase;//'50' is the meter charge and "phase" is the service charge
bill_synopsis();
}
void Small_Industry()//function of small Industry category
{
float flatrate,off_peaktime,peaktime;
//taking the value of units consumed at flat rate, off-peak time and peak time as input from the
user.
printf("Enter units consumed at flat rate:");
scanf("%f",&flatrate);
printf("Enter units consumed at off-peak time:");
scanf("%f",&off_peaktime);
printf("Enter units consumed at peak time:");
scanf("%f",&peaktime);
bill=bill+(flatrate*7.66)+(off_peaktime*6.90)+(peaktime*9.24)+50+70;//'70' is the service
charge, '50' is the meter charge.
bill_synopsis();//calling the bill synopsis function again so that our meter replacement charge
gets added with the bill.
}
void Non_Residential()//function of Non-residential category
{
float c_unit;//c_unit variable denotes the units of electricity consumed by the customer
printf (" Units Consumed by the Customer :");
scanf("%f",&c_unit);
int phase;
printf("1.1-Phase\n2.3-Phase\nEnter your choice:");
scanf("%d",&phase);
if(phase==1){
phase=10;
}
else{
phase=30;
}
bill=bill+(c_unit*5.22)+50+phase;//'phase' is the service charge, '50' is the meter charge, 5.22
is the per unit rate of Non-residential
bill_synopsis();//calling the bill synopsis function so that our meter replacement charge gets
added with the bill.
}
}
void Main_Menu()//function of Main Menu
{
printf("\n1. Monthly Bill \n");
printf("2. Meter Replacement \n");
printf ("3. Main Menu \n");
printf("4. Exit\n");
int c_choice1;//this variable denotes the customer choice of Main Menu
printf(" Dear Customer, please enter your choice :");
scanf("%d",&c_choice1);//taking customer's choice as input
if(c_choice1==1)
{
Monthly_Bill();//calling the function Monthly_bill() if the customer puts c_choice1 '1' as input
}
else if(c_choice1==2)
{
Meter_Replacement();//calling the function Meter_Replacement() if the customer puts
c_choice1 '2' as input
}
else if(c_choice1==3)
{
c_data();//calling function 'c_data' as we need the customer's information again.
}
else if(c_choice1==4)
{
exit(0);//exit(0) is a default function of #include<stdlib.h>
}
}
void c_data()//'void' type since the function won't return anything and it is declared as a function
in case customer data is needed again in the future.
{
bill = 0;//this is set zero as for every new customer the previous bill needs to be reset and this
thing is done in this function because whenever a new customer comes, this c_data() function
will be called.
//this function is taking the customer name and number as input from the user and is calling
the 'Main_Menu' function'
replace=0;//replacement is set as zero for new customer
printf(" ~~~~~~~~~~Check Your Electricity Bill~~~~~~~~~~\n");
printf("Enter the name of the customer :");
scanf("\n%[^\n]s",c_name);//taking customer name as input from the user
printf("Customer Number :");
scanf("%d",&c_number);//taking customer number as input from the user
printf("\nXXXXX\n");
Main_Menu();//calling function Main_Menu and Main_Menu will not have any parameters
}
void main ()//main function won't return anything so it will be of 'void' type.
{
c_data();//'c_data' contains the information of the customer and it does not have any
parameter
}