<< Chapter < Page Chapter >> Page >

2.6) Write a C++ program to compute the sum and average of N single-precision floating point numbers entered by the user. The value of N is also entered by the user.

2.7) The value of Euler constant, e, is approximated by the following series:

e = 1 + 1/1! +1/2! + 1/3! + 1/4! + 1/5! + …

Using this series, write a C++ program to compute e approximately. Use while structure that terminates when the difference between two successive approximations becomes less than 1.0E-6.

2.8) Write a C++ program to calculate and display the amount of money accumulated in a saving bank account at the end of each year for 10 years when depositing 1000$ in the bank. The program has to display the amount of money when interest rates change from 6% to 12% with the increment 1%. Thus, you should use two nested loops: the outer loop iterates according to interest rates and the inner loop iterates according to the years.

2.9) Write a C++ program that inputs a positive integer n and lists out n first prime numbers.

2.10) Write a C++ program to display an equilateral triangle with the height h (h is entered from the user). Example: h = 4

Lab session 4: arrays

1. objective

The objective of Lab session 4 is to get familiar with arrays, one-dimensional and two-dimensional arrays.

2. experiment

2.1) Test the following program.

#include<iostream.h>

const int NUM = 8;

void main()

{

int nums[NUM];

int total = 0; // Holds total of user’s eight numbers.

int ctr;

for (ctr=0; ctr<NUM; ctr++)

{

cout<<“Please enter the next number...”;

cin>>nums[ctr];

total += nums[ctr];

}

cout<<“The total of the numbers is “<<total<<“\n”;

return;

}

2.2) If the array weights is declared as in the following statement, then what the value of weights[5] is ?

int weights[10] = {5, 2, 4};

2.3) Given the statement:

char teams[] = {‘E’,’a’,’g’,’l’,’e’,’s’,’\0', ’R’, ‘a’,’m’,’s’,’\0'};

which of the following statement is valid?

a. cout<<teams;

b. cout<<teams+7;

c. cout<<(teams+3);

d. cout<<teams[0];

e. cout<<(teams+0)[0];

f. cout<<(teams+5);

2.4) Given the array declaration:

int grades[3][5]= {80,90,96,73,65,67,90,68,92,84,70, 55,95,78,100};

Determine the value of the following subscripted variables:

a. grades[2][3]

b. grades[2][4]

c. grades[0][1]

2.5) Write a C++ program that inputs an array consisting of n single-precision floating point numbers and finds the smallest element in the array. (n is an integer that is entered by the user).

2.6) Write a C++ program that inputs an integer array and finds the last element in the array.

2.7) Write a C++ program that inputs an integer array and then inserts the integer value X in the first position in the array.

2.8) Write a C++ program that inputs an integer array and checks if all the elements in the array are unique (i.e. we can not find any pair of elements that are equal to each other).

2.9) Write a C++ program that inputs a matrix and then transposes it and displays the transposed matrix. Transposing a square matrix is to swap:

a(i,j)<==>a(j,i) for all i, j

For example, given the matrix

After transposing it, it becomes as follows:

Questions & Answers

how does Neisseria cause meningitis
Nyibol Reply
what is microbiologist
Muhammad Reply
what is errata
Muhammad
is the branch of biology that deals with the study of microorganisms.
Ntefuni Reply
What is microbiology
Mercy Reply
studies of microbes
Louisiaste
when we takee the specimen which lumbar,spin,
Ziyad Reply
How bacteria create energy to survive?
Muhamad Reply
Bacteria doesn't produce energy they are dependent upon their substrate in case of lack of nutrients they are able to make spores which helps them to sustain in harsh environments
_Adnan
But not all bacteria make spores, l mean Eukaryotic cells have Mitochondria which acts as powerhouse for them, since bacteria don't have it, what is the substitution for it?
Muhamad
they make spores
Louisiaste
what is sporadic nd endemic, epidemic
Aminu Reply
the significance of food webs for disease transmission
Abreham
food webs brings about an infection as an individual depends on number of diseased foods or carriers dully.
Mark
explain assimilatory nitrate reduction
Esinniobiwa Reply
Assimilatory nitrate reduction is a process that occurs in some microorganisms, such as bacteria and archaea, in which nitrate (NO3-) is reduced to nitrite (NO2-), and then further reduced to ammonia (NH3).
Elkana
This process is called assimilatory nitrate reduction because the nitrogen that is produced is incorporated in the cells of microorganisms where it can be used in the synthesis of amino acids and other nitrogen products
Elkana
Examples of thermophilic organisms
Shu Reply
Give Examples of thermophilic organisms
Shu
advantages of normal Flora to the host
Micheal Reply
Prevent foreign microbes to the host
Abubakar
they provide healthier benefits to their hosts
ayesha
They are friends to host only when Host immune system is strong and become enemies when the host immune system is weakened . very bad relationship!
Mark
what is cell
faisal Reply
cell is the smallest unit of life
Fauziya
cell is the smallest unit of life
Akanni
ok
Innocent
cell is the structural and functional unit of life
Hasan
is the fundamental units of Life
Musa
what are emergency diseases
Micheal Reply
There are nothing like emergency disease but there are some common medical emergency which can occur simultaneously like Bleeding,heart attack,Breathing difficulties,severe pain heart stock.Hope you will get my point .Have a nice day ❣️
_Adnan
define infection ,prevention and control
Innocent
I think infection prevention and control is the avoidance of all things we do that gives out break of infections and promotion of health practices that promote life
Lubega
Heyy Lubega hussein where are u from?
_Adnan
en français
Adama
which site have a normal flora
ESTHER Reply
Many sites of the body have it Skin Nasal cavity Oral cavity Gastro intestinal tract
Safaa
skin
Asiina
skin,Oral,Nasal,GIt
Sadik
How can Commensal can Bacteria change into pathogen?
Sadik
How can Commensal Bacteria change into pathogen?
Sadik
all
Tesfaye
by fussion
Asiina
what are the advantages of normal Flora to the host
Micheal
what are the ways of control and prevention of nosocomial infection in the hospital
Micheal
what is inflammation
Shelly Reply
part of a tissue or an organ being wounded or bruised.
Wilfred
what term is used to name and classify microorganisms?
Micheal Reply
Binomial nomenclature
adeolu
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Programming fundamentals in c++. OpenStax CNX. Jul 29, 2009 Download for free at http://cnx.org/content/col10788/1.1
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Programming fundamentals in c++' conversation and receive update notifications?

Ask