Conditional Statements, Repetition-Introduction to Programming-Assignment, Exercises of Computer Programming

I am student at Baddi University of Emerging Sciences and Technologies. To help my friends in other universities, I am uploading my assignments of different courses. Its for Theory of Automata and Introduction to Programming course. Other can see if they are searching following: Instructions, Language, Programming, Conditional, Statements, Repetition, Structures, Switch, Compiling, Executing

Typology: Exercises

2011/2012

Uploaded on 08/01/2012

parmitaaaaa
parmitaaaaa 🇮🇳

4.2

(111)

173 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Assignment No. 01
Semester: Spring 2012
CS201: Introduction to Programming
Total Marks: 20
Due Date:16/04/2012
Instructions:
Please read the following instructions carefully before submitting
assignment. It should be clear that your assignment will not get any credit
if:
The assignment is submitted after due date.
The submitted assignment does not open or file is corrupt.
Assignment is copied(partial or full)
f
rom any source (websites,
forums, students, etc)
Note: You have to upload only .cpp file.
A
ssignment in any other format
(extension) will not be accepted and will be awarded with zero marks.
F
or
example, if you submit code in .doc (Word document) or .txt files, no reward
will be given in any case.
Objective:
The objective of this assignment is to provide hands on experience of:
Basic concepts of C/C++ language and Programming
Conditional statements if/else structure
Repetition Structures in C/C++
Switch statement in C/C++
Saving a program
Compiling a program
Executing the program
Guidelines:
Code should be properly indented and well commented.
Follow C/C++ rules while writing variable names, function names etc
Use only dev-C++ for this assignment.
docsity.com
pf3
pf4

Partial preview of the text

Download Conditional Statements, Repetition-Introduction to Programming-Assignment and more Exercises Computer Programming in PDF only on Docsity!

Assignment No. 01 Semester: Spring 2012 CS201: Introduction to Programming

Total Marks: 20

Due Date:16/04/

Instructions:

Please read the following instructions carefully before submitting

assignment. It should be clear that your assignment will not get any credit

if:

 The assignment is submitted after due date.  The submitted assignment does not open or file is corrupt.  Assignment is copied(partial or full) from any source (websites, forums, students, etc)

Note: You have to upload only .cpp file. Assignment in any other format (extension) will not be accepted and will be awarded with zero marks. For example, if you submit code in .doc (Word document) or .txt files, no reward will be given in any case.

Objective:

The objective of this assignment is to provide hands on experience of:

 Basic concepts of C/C++ language and Programming  Conditional statements if/else structure  Repetition Structures in C/C++  Switch statement in C/C++  Saving a program  Compiling a program  Executing the program

Guidelines:

 Code should be properly indented and well commented.  Follow C/C++ rules while writing variable names, function names etc  Use only dev-C++ for this assignment.

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..

 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.

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.