Write a program to calculate the SPI(semester performance index) and CPI(Cumulative Performance Index) of a student taking N courses in a semester. Each course has a specified weight, termed as credit and a student secures a letter grade in that course as per the Grading System.
The Grading System is as follows:
Letter Grade Numerical Grade
A 10
B 9
. .
. .
K 0
Note that the numerical grade can be obtained from the letter grade using arithmetic operations on char type data.
Write a program that reads in a number n and prints out asterisks(‘*’) in the shape of a
rectangle having n rows and 2*n columns. Thus for n=3 your program should print
******
******
******
The equation f(x) ≡ (1 − x) cos x − sin x = 0 has at least one root between a = 0 and
b = 1 since f(a)f(b) < 0. The bisection method of finding the root proceeds as follows:
a. It finds the midpoint r = (a + b)/2.
b. If f(r) = 0, then r is the root. If |b − a| is very small less than , then also we can
take r as the root. In either of the cases, our job is done.
c. If f(r) 6= 0 and f(a)f(r) < 0, then the root lies between a and r. We assign r to b
and go to step a.
d. If f(r) 6= 0 and f(b)f(r) < 0, then the root lies between r and b. We assign r to a
and go to step a.
e. If the number of iterations is high, we may stop the process with appropriate message.
Write the following functions with the specifications mentioned.
1. Function func takes a real number x as argument and returns the value of f(x).
2. Function cbracket takes two real numbers a and b as arguments and returns 1 if at
least one real root of f(x) lies between a and b, and 0 otherwise.
3. Function rootb that takes three real numbers a, b, eps and an integer Nmax as argu-
ments. This function returns the root of f(x) = 0 using bisection method. If the number
of iteration is more than Nmax then the function terminates with appropriate message.
Write a C program using the above functions. This program accepts a, b, eps and Nmax
from the keyboard and prints out the root
Write a program to convert kilogram to grams by passing pointers as arguments to the
function.
Write a program in C++ to find the maximum number between two numbers using a pointer.
Test Data :
Input the first number : 5
Input the second number : 6
Expected Output :6 is the maximum number.
Write a C++ function to sort an array of ten integer values in ascending order.
Write a C++ program to accept five integer values in an array using pointer offset notation.
Write a program that reads in a number and prints out the letter L using '*' characters
with each line in the L having width n. Further, the length of the horizontal bar should be
4n, and that of the vertical bar (i.e. not including the portion overlapping with the
horizontal bar) should be 3n. Thus for n=3 your program should print
***
***
***
***
***
***
***
***
***
************
************
************
OutputTest Case 1
*
*
*
****
Test Case 2
**
**
**
**
**
**
********
********
Test Case 3
****
****
****
****
****
****
****
****
****
****
****
****
****************
****************
****************
****************Write a program that reads in a number and prints out the letter L using '*' characters
with each line in the L having width n. Further, the length of the horizontal bar should be
4n, and that of the vertical bar (i.e. not including the portion overlapping with the
horizontal bar) should be 3n. Thus for n=3 your program should print
***
***
***
***
***
***
***
***
***
************
************
************
OutputTest Case 1
*
*
*
****
Test Case 2
**
**
**
**
**
**
********
********
Test Case 3
****
****
****
****
****
****
****
****
****
****
****
****
****************
****************
****************
****************Write all answers for Question 2 in C++ syntax.
3.2
3.2.1 Write a C++ program that will randomize three values and determine and display
which one is the highest and which one is the lowest. Range (From 1 to 350)
3.2.2 Re-write 3.2.1 by using two functions, one called determineLarge and one
called determineSmall.
3.2.3 Re-write 3.2.1 by using a single function determineLargeSmall.
Question 4
4.1.1 Students in Computer Science would like to understand the concept of Ohm’s law. You
are required to write an application that will allow them to calculate the relation
between Voltage, Current and Resistance using the formulas below.
V = IR
Current (I) = V/R
Resistance= V/I
(where I is the current, V - Voltage and R is the resistance)
4.1.1 Write a program that will assist the students:
4.1.2 Create a C++ source file called OLaw and save it in a file called OLaw.cpp.
4.2 Create the following functions:
4.2.1 calcVoltage() This function must calculate the voltage in a circuit using the
information given above.
4.2.2 calcCurrent() This function must calculate the current charge using the information
given above.
4.2.3 calcResistance() This function must calculate the resistance of the flow using the
information given above.
4.2.4 main() NB: The functions must be implemented above the main.
Add all necessary pre-processor directives.
Declare all constants and necessary variables.
Prompt the user for the calculation he/she would like to see
(I/I, V/v, R/r)(See Figure 4.1).