0% found this document useful (0 votes)
12 views

Assignment 1

The document provides instructions for students to submit assignments for a programming course. It includes: 1) Instructions on naming program files and output files with the assignment number, student roll number, and file extensions. 2) Three programming assignments - (a) calculating the perimeter of a triangle given vertex coordinates, (b) calculating compound interest given principal and interest rate/time, and (c) calculating power dissipated in resistances in a circuit. 3) Input data sets provided for testing the programs. 4) Instructions for students to generate output files by redirecting program output and to submit all assignment results together in a single file.

Uploaded by

jitbitan.kgpian
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Assignment 1

The document provides instructions for students to submit assignments for a programming course. It includes: 1) Instructions on naming program files and output files with the assignment number, student roll number, and file extensions. 2) Three programming assignments - (a) calculating the perimeter of a triangle given vertex coordinates, (b) calculating compound interest given principal and interest rate/time, and (c) calculating power dissipated in resistances in a circuit. 3) Input data sets provided for testing the programs. 4) Instructions for students to generate output files by redirecting program output and to submit all assignment results together in a single file.

Uploaded by

jitbitan.kgpian
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Assignment-I

Write your name, roll number and assignment number in the header of the
program file as comments. You may give your program file name as
<asgn><no_><RollNo>.c. For example, a student with roll number 21CS1001
should name the program file for assignment number 1(a), as
asgn1a_21CS1001.c. Submit all the programs in the Moodle System 15 minutes
before the end of the laboratory session. Provide also output files containing
results given the set of inputs given here. Please follow the instruction for
generating result files provided at the end.

(a) Compute the perimeter of a triangle given its coordinates of its three
vertices (to be read).

Input data set (coordinates of three vertices of a triangle)

(i) (10,5), (-5,3), (2,2)


(ii) (1,2), (5,5), (7,6.5)
(iii) (0,0,), (5,0), (2.5, 5)

(b) Compute the compound interest of a principal amount p (to be read) at an


interest rate of 5.5% for n (to be read) years.

Input data set:

(i) p=10000, n=4


(ii) p=4563, n=3

(c) Consider a resistive circuit (shown in a Figure overleaf) where a


resistance R1 is connected with two resistances R2 and R3 connected in parallel.
A D.C. source E is applied across this load. Compute the power dissipated in
each resistance, and the total power consumed by the circuit. Assume the values
of resistance given in ohm, power source in Volt, and power should be
expressed in Watt. Write a program which will read the values of resistances
and power source and print the results (as asked) of the computation.
(i) R1=5 KW, R2=10 KW, R3=20 KW, E=50 V
(ii) R1=15 KW, R2=7 KW, R3=8 KW, E=12 V
For generation of output files

All the results for each assignment should be submitted together in a separate
file (named result.txt). Provide the result in a separate output file (named,
result_<assgn><no>.txt). Use standard output redirection feature to generate
the output file.

Hints. Suppose you would like to redirect your output to a file ‘result.txt’.
If you run the program with the following command

./a.out >result.txt

Output of your program (generated by printf(.) function) will be written


in file result.txt. You need to provide input from your input, by
remembering the sequence of inputs to be given.

If you execute the program multiple times, you may concatenate the
outputs in a single file by using the following redirection command:

./a.out >>result.txt

Input redirection (optional):

You may also store your input (the ordering as per requirement of
the program should be preserved) in an input file in.txt, and execute the
program as follows:

./a.out <in.txt >result.txt

You might also like