www.vustudents.ning.com

We non-commercial site working hard since 2009 to facilitate learning Read More. We can't keep up without your support. Donate.

# CS201 Assignment No 1 Solution & Discussion Due Date:16-04-20112

 Assignment Problem Statement:     Challan Calculator for Traffic Violation       You are required to write a program for calculating challan for traffic violations. The basic idea is that user will enter the type of violation and number of days passed till date of challan. The challan calculator will calculate the challan based upon the type of violation and number of days.   Detailed Description:   You are required to take input from user for type of traffic violation. User will enter ‘1’ if the violation type is “For breaking traffic signal” User will enter ‘2’ if the violation type is “For over speeding” User will enter ‘3’ if the violation type is “For not wearing seat belt” If user enters any other number except 1, 2 or 3, the program will print a message “Enter a valid type of traffic violation”. After printing this message program will start again from beginning and prompt user to enter the valid type of traffic violation. If user enters ‘1’ the amount of fine is Rs.500, if ‘2’ then Rs.300 and if user enters ‘3’ then fine will be Rs.200.   Now, program will prompt user to enter number of days passed till challan date. If number of days are less than or equal to 10, then the total challan will be same as amount of fine. If number of days are more than 10 or less than/equal to 30, then total challan will be double of amount of fine. If number of days are more than 30, then 50% of fine will be added in double of amount of fine. i.e. 2 times fine + 1/2 times fine.   After displaying the total challan to user, the program should ask if the user wants to calculate another challan. The user can enter ‘y’ or ‘n’ as choices for yes or no. Program will handle user’s choice in both upper and lower cases.   If the user enters ‘y’ or ‘Y’, then program should clear the screen and start the whole process again or terminate the program otherwise.       Sample Output:   In the following screenshot, user entered 2 as violation type and 20 as number of days passed till challan. After showing the calculated challan, program prompts user whether he/she wants to calculate another challan.       User entered y as choice and the program has started the whole process from beginning again.           After showing the error message, the program starts the whole process again upon user presses any key from the keyboard.     Hints: You can use switch statement to check the type of traffic violation. Use appropriate loop for starting the whole program from beginning after user enters his/her choice. To clear the screen you should use system(“cls”); function. Also the use of if/else structure, continue statement and getch() function (available in conio.h header file) can be helpful in solving this assignment.

Views: 1964

Attachments:

### Replies to This Discussion

THANKSSSSSSSSSSSSSSSSSSS

FOR SOLUTION FILE

no solution yet?

It is such an easy assignment. Give it a try yourself.

please check it out my solution that i post for u, need any help feel free to contact me at tahirramzan1@yahoo.com

CS201 Assignment No 1 Solution Spring 2012

Attachments:

CS201 Assignment#1 Solution

One more idea solution

Attachments:

CS201 1st Assignment Solution spring 2012

Solution :

#include<iostream.h>
main(){
// declaring variables to save data in the programe
int volType, amountOfFine, noOfDays;
char choice;

// Taking input from the user
a: cout"*****CHALLAN CALCULCULATION FOR TRAFFIC VOILATION ******** ";
cout"{Enter '1' for breaking traffic signal"endl;
cout"Enter '2' for over speeding"endl;
cout"Enter '3' for not wearing seat belt }"endl;
cout"Please Enter the Voilation Type (1,2 or 3) : ";
cin>>volType;

// cheking the validity of the input givn by the user
if(volType>3||volType<1)
{
coutvolType" Is an Invalid Choice Please Enter a valid type of traffic violation : ";
goto a; }
if(volType==1)
{

amountOfFine=500;
}else if(volType==2)
{
amountOfFine=300;
}else if(volType==3)
{

amountOfFine=200;
}

// taking input from user
cout"Please Enter the No. Of Days till Challan : ";
cin>>noOfDays;
// After Calculating the Amount of fine giving feed back to the User
if(noOfDays<=10)
{

cout"The Total Amount of Challan =" amountOfFineendl;
}else if(noOfDays>10&&noOfDays<=30)
{

cout"The Total Amount of Challan =" amountOfFine+amountOfFineendl;
} else if(noOfDays>30)
{

cout"The Total Amount of Challan =" amountOfFine+amountOfFine+amountOfFine/2endl;

cout"\N Do you want to mak another calculation! Press Y for yes and press N for No"endl;
cin>>choice;
// Lopeing back to the Next calculation on users choice
while (choice=='y'||choice=='Y')
{goto a;}
cout "Take Care Allah Hafiz" endl;
system("PAUSE");
}

One another More Solution :

#include<iostream.h>
#include<conio.h>

main()

{
char i;
int a, b;

do

system("cls");
cout"******Challan Calculator for Traffic Violations******";
coutendl;
coutendl;
cout"Enter '1' for Breaking Signal:";
coutendl;
cout"Enter '2' for Over Speed:";
coutendl;
cout"Enter '3' for Wearing not Seat Belt:";
coutendl;
coutendl;
cout"Enter the type of traffic violation 1, 2 or 3:";
cin>>a;
coutendl;
switch(a)
{
case 1:
cout"Enter the numbers of days passed till challan date:";
cin>>b;
coutendl;

if(b<=10)cout"The total fine is Rs: "500;
else if (b<=30)cout"The total fine is Rs: "500*2;
else if (b>30)cout"The total fine is Rs: "(500*2)+(500/2);
break;
case 2:
cout"Enter the numbers of days passed till challan date:";
cin>>b;
coutendl;

if(b<=10)cout"The total fine is Rs: "300;
else if (b<=30)cout"The total fine is Rs: "300*2;
else if (b>30)cout"The total fine is Rs: "(300*2)+(300/2);

break;
case 3:
cout"Enter the numbers of days passed till challan date:";
cin>>b;
coutendl;

if(b<=10)cout"The total fine is Rs: "200;
else if (b<=30)cout"The total fine is Rs: "200*2;
else if (b>30)cout"The total fine is Rs: "(200*2)+(200/2);
break;
default:
coutendl;
coutendl;
cout"Please Enter a Valid Type of Traffic Violation:";
coutendl;
coutendl;
getch();
coutendl;
coutendl;
system("cls");
main();
break;

}

coutendl;
coutendl;
cout"Do you want another challan calculation? (y/n):";
cin>>i;
}
while(i != 'N' && i != 'n' );

}

What is endl

Assignment No 1 CS201 2012 Solution

see the attached folder

Attachments:

Enjoy this...... When i was in first semester i got 00 marks in first assignment but i swear that i solve each VU assignment .. for students ...

Attachments:
CS201 Perfect Solution of 1st Assignment spring 2012.

#include<iostream.h>
main(){

int choice, days, fine;
char op;
cout"**********************************************"endl;
cout" Challan Calculator for Traffic Violation "endl;
cout"**********************************************"endl;
while(1){
coutendl;
cout" Enter '1' for breaking signals"endl;
cout" Enter '2' for over Speeding"endl;
cout" Enter '3' for not wearing seat belt"endl;
coutendl;
cout"Enter a type of traffic violation(1 , 2 , 3) :";
cin>>choice;

if(choice == 1 || choice == 2 || choice == 3){

switch(choice){

case 1:
cout"Enter the number of days passed till challan date :";
cin>>days;
if(days <= 10){
coutendl;
cout"The Total Challan is : "500" Rs"endl;
}else
if(days > 10 && days<=30){
coutendl;
cout"The Total Challan is : "500*2" Rs"endl;
}else{
coutendl;
cout"The Total Challan is : "500*2+((500*2)/2.0)" Rs"endl;
}
break;

case 2:
cout"Enter the number of days passed till challan date :";
cin>>days;
if(days <= 10){
coutendl;
cout"The Total Challan is : "300" Rs"endl;
}else
if(days > 10 && days<=30){
coutendl;
cout"The Total Challan is : "300*2" Rs"endl;
}else{
coutendl;
cout"The Total Challan is : "300*2+((300*2)/2.0)" Rs"endl;
}
break;
case 3:
cout"Enter the number of days passed till challan date :";
cin>>days;
if(days <= 10){
coutendl;
cout"The Total Challan is : "200" Rs"endl;
}else
if(days > 10 && days<=30){
coutendl;
cout"The Total Challan is : "200*2" Rs"endl;
}else{
coutendl;
cout"The Total Challan is : "200*2+((200*2)/2.0)" Rs"endl;
}
}

}else{
cout"Enter a valid type of traffic violation"endl;
}
coutendl;
cout"Do you want to calculate another Challan [Y][N] :";
cin>>op;
if(op=='y' || op == 'Y'){
continue;
}else

coutendlendl;
cout"-----------------------------"endl;
cout"Thank you for paying challan "endl;
cout" PAKISTAN TRAFFIC POLICE "endl;
cout"-----------------------------"endl;
break;
}
}
system("pause");
}

1

2

3

4

5

## VIP Member Badge & Others

------------------------------------

## Latest Activity

1 hour ago
Ishrat Shaheen joined + M.Tariq Malik's group

### CS607 Artificial Intelligence

2 hours ago
MUHAMMAD USMAN added a discussion to the group CS101 Introduction to Computing

5 hours ago
Pizza updated their profile
14 hours ago
naveed asmat mirza and Zain Arshad joined + M.Tariq Malik's group

### CS304 Object Oriented Programming

15 hours ago
15 hours ago
Asad waqas joined + M.Tariq Malik's group

15 hours ago
16 hours ago