<< Chapter < Page Chapter >> Page >

2.4) Write a C++ function that checks if a square matrix with order of n is symmetric or not. And then write a C++ program that inputs a square matrix with order of n and then checks if it is symmetric or not.

2.5) A palindrome is a string that reads the same both forward and backward. Some examples are

Given the following function that returns true if the parameter string is a palindrome or false , otherwise.

bool palindrome(char strg[])

{

int len, k, j;

len = strlen(strg);

k = len/2;

j = 0;

bool palin = true;

while ( j<k&&palin)

if (strg[j] != strg[len -1-j])

palin = false;

else

++ j;

return (palin)

}

Write a C++ program that reads several strings, one at a time and checks if each string is a palindrome or not. Use a while loop in your program. The loop terminates when the user enters a string starting with a ‘*’.

2.6) Write a boolean function that can checks if all the elements in integer array are unique (i.e. we can not find any pair of elements that are equal to each other).

Write a C++ program that inputs an integer array and invokes the function to check if all the elements in integer array are unique.

2.7) Given the following formula for computing the number of combinations of m things out of n, denote C(n, m).

C(n, m) = 1 if m = 0 or m=n

C(n, m) = C(n-1, m) + C(n-1, m-1) if 0<m<n

  1. Write a recursive function to compute C(n,m).
  2. Write a complete C++ program that reads two integers N and M and invokes the function to compute C(N,M) and prints the result out.

2.8) The greatest common divisor of two positive integers is the largest integer that is a divisor of both of them. For example, 3 is the greatest common divisor of 6 and 15, and 1 is the greatest common divisor of 15 and 22. Here is a recursive function that computes the greatest common divisor of two positive integers:

int gcd(int p, int q)

{

int r ;

if (( r = p%q == 0)

return q ;

else

return gcd(q, r) ;

}

a. First write a C++ program to test the function.

b. Write and test an equivalent iterative function.

Lab session 7: pointers

1. objective

The objectives of Lab session 7 are to get familiar with how to use pointers in C++.

2. experiment

2.1) Run the following program to determine the size of two data types long and byte.

# include<iostream.h>

void main()

{

byte* a;

long* b;

cout<<sizeof(a)<<endl;

cout<<sizeof(b)<<endl;

}

2.2) Given the following code segment:

float pay;

float *ptr_pay;

pay=2313.54;

ptr_pay =&pay;

determine the values of the following expressions:

a. pay

b. *ptr_pay

c. *pay

d.&pay

2.3) Read for understanding the following program:

#include<iostream.h>

void main()

{

int a;

int *aPtr; // aPtr is a pointer to an integer

a = 7;

aPtr =&a; //aPtr set to address of a

cout<<“The address of a is “<<&a

<<“\nThe value of aPtr is “<<aPtr;

cout<<“\n\nThe value of a is “<<a

<<“\nThe value of *aPtr is “<<*aPtr

<<endl;

}

Run the program and explain the output.

2.4) Given the following array and pointer declarations:

int ara[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

int *ip1, *ip2;

Determine which of the following assignments are valid.

a. ip1 = ara;

b. ip2 = ip1 =&ara[3];

Questions & Answers

What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
?
Kyle
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
Adin
why?
Adin
what school?
Kyle
biomolecules are e building blocks of every organics and inorganic materials.
Joe
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
research.net
kanaga
sciencedirect big data base
Ernesto
Introduction about quantum dots in nanotechnology
Praveena Reply
what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
Bharti
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
Damian Reply
absolutely yes
Daniel
how to know photocatalytic properties of tio2 nanoparticles...what to do now
Akash Reply
it is a goid question and i want to know the answer as well
Maciej
characteristics of micro business
Abigail
for teaching engĺish at school how nano technology help us
Anassong
Do somebody tell me a best nano engineering book for beginners?
s. Reply
there is no specific books for beginners but there is book called principle of nanotechnology
NANO
what is fullerene does it is used to make bukky balls
Devang Reply
are you nano engineer ?
s.
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
Tarell
what is the actual application of fullerenes nowadays?
Damian
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
Tarell
what is the Synthesis, properties,and applications of carbon nano chemistry
Abhijith Reply
Mostly, they use nano carbon for electronics and for materials to be strengthened.
Virgil
is Bucky paper clear?
CYNTHIA
carbon nanotubes has various application in fuel cells membrane, current research on cancer drug,and in electronics MEMS and NEMS etc
NANO
so some one know about replacing silicon atom with phosphorous in semiconductors device?
s. Reply
Yeah, it is a pain to say the least. You basically have to heat the substarte up to around 1000 degrees celcius then pass phosphene gas over top of it, which is explosive and toxic by the way, under very low pressure.
Harper
Do you know which machine is used to that process?
s.
how to fabricate graphene ink ?
SUYASH Reply
for screen printed electrodes ?
SUYASH
What is lattice structure?
s. Reply
of graphene you mean?
Ebrahim
or in general
Ebrahim
in general
s.
Graphene has a hexagonal structure
tahir
On having this app for quite a bit time, Haven't realised there's a chat room in it.
Cied
what is biological synthesis of nanoparticles
Sanket Reply
what's the easiest and fastest way to the synthesize AgNP?
Damian Reply
China
Cied
how did you get the value of 2000N.What calculations are needed to arrive at it
Smarajit Reply
Privacy Information Security Software Version 1.1a
Good
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!





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