Escolar Documentos
Profissional Documentos
Cultura Documentos
+
Never afraid for such codes . again
LPWIN32_FIND_DATA FindFirstHelper::ResetFindData(){
if(findData == NULL)
{findData = new WIN32_FIND_DATA;}
else{::FindClose(findFirstHandle);
}
return findData;
}
bool
FindFirstHelper::FindFirst(const
char
*filePattern){
ResetFindData();
#if 0
// gmc revist: we should handle UNC filenames here
as well
string UNCAware = "\\\\?\\";
UNCAware += filePattern;
findFirstHandle
=
::FindFirstFileW(UNCAware.c_str(), findData);
#else
string UNCAware = filePattern;
findFirstHandle
=
::FindFirstFileA(UNCAware.c_str(), findData);
#endif
Practical approach
Solved exercises and assignments and test
questions
Page 1 of 17
BY Musa Mustapha
#include <string>
#include <conio>
the result on screen
int main ( )
// opening braces
char answer;
// declaration
if (answer==yes)
// conditional statement
Caution!
Whenever you see double slash like this // means a comment or
an explanatory statement for you to understand, it does not
have an effect of the execution of the program
Page 2 of 17
Prefatory
I purposefully compose this solutions to our dear colleagues
problem from other department, who petrified of C++ course,
going by the last test most of us already forecast our result in
programing and found likely to be below average. This
minuscule pages will give you an understanding, a good grade in
programming course. I surprise why our colleagues from other
department afraid of programming, it is too simple and very
elementary at this stage, may be the tricky is most of us dearth
the practical aspect or terrified of computer operating.
Moreover, most of us find this course as invaluable to our
studies especially EMT and Mathematics students. I learnt that
you misunderstood the course as a result of deficiency of
familiarity in application of programming into your major.
Nowadays, computer has become part of human being
activities, no organisation, academic or any field can do without
computer, therefore possession of computer knowledge can
helps us in one way or the other in future time.
However, it wasnt too late for you to earn a very good grade in
Jungle++, at least you have an outstanding time toward
examination for you to earn a good grade at least a A or B+
in programming problem.
C++ does not required a much computational experience nor
mastering an equations, it only need understanding of the
concept behind the scene. So now its time to blast the secret
behind the scene, thats why, I intent to summarised the basic
area covered from the courseware and solve an assignments,
lab exercise and test questions, so that it will support us in our
study toward imminent examination by the grace of Allah.
Page 3 of 17
Week 1 exercise
Lab Questions
Q1. Identify any real world problem and provide a suitable solution using
your knowledge of problem solving methodology.
Solution to the Problem of drafting multiplication table
#include <iostream>
#include <iomanip>
#include <conio>
//program to generate multiplication table using for loop nested
statement
int main ( )
{
int row , column;
for (row=1; row<=12; row++)
{
for (column=1;column<=12;column++)
{
cout<<setw(5)<<row*column;
}
cout<<endl;
}
Page 4 of 17
getch ( );
}
This will be the output of the above program.
Week 2 exercise
Lab Questions
Q1. Write a program that will prints the following x` shape:
*
*
*
**
*
* *
*
*
*
*
Solution
#include <iostream>
#include <conio>
//program to display the shape of x;
int main ( )
{
cout<<
*
*
cout<<
*
*
cout<<
*
*
<<endl;
<<endl;
<<endl;
Page 5 of 17
cout<<
cout<<
cout<<
cout<<
getch ();
}
*
*
*
*
*
*
<<endl;
<<endl;
<<endl;
* <<endl;
Q2. Write a program to compute and output the perimeter of and area of
a circle having a radius of 3m
Solution
#include <iostream>
#include <conio>
//program to computer area and perimeter of a circle;
int main ( )
{
float area, perimeter;
int radius;
radius = 3;
area = 2*3.142*radius*radius;
perimeter = 3.142*radius*radius;
cout<< the area of a circle having 3 meter radius is
<<area<<endl;
cout<< the perimeter of a cirle having 3 meter radius is
<<perimeter<<endl;
getch ( );
}
Q3. Write a program that will allow inputting two integer numbers,
subtract the first integer from the second integer and display the result
on the screen.
Assume your variables are x and y;
solution
#include <iostream>
#include <conio>
int main ( )
{
int x, y;
float result;
cout<< enter a the value of y <<endl;
cin>>y;
cout<<enter a the value of x<<endl;
cin>>x;
result = (x y);
Page 6 of 17
Week 3
Lab Questions
1. Write a program that store the detail of your bank account. Declare
Name of the bank, Account Name, Account Type, Account Number
and Current Balance as your variables, assign values and display
them on the screen.
#include <iostream>
#include <string>
#include <conio>
int main ( )
{
char bank_name, account_name, account_type, account_number,
current_balance;
bank_name = first bank plc;
Page 7 of 17
Week 4 exercise
Lab Questions
1. Write a program(s) to I identify between the differences between
pre- incrementation and post incrementation
#include < iostream>
#include < conio>
Page 8 of 17
Week 5
Lab Questions
Q1. Write a program that will takes value from the user and print its
square and cube unless it is more than 180. The message ***square
is not allowed for numbers over 180*** appear on - screen.
#include <iostream>
#include <conio>
int main ( )
{
Page 9 of 17
Page 10 of 17
if(n>0)
cout<< the number is positive<<endl;
if(n<=0)
cout<< the number is less than or equal to zero<<endl;
getch ( );
}
Q4. Write program that will ask the user for his or her first name,
and then stores it in a character array. The program checks the first
character of the array to see whether it falls in the first half of the
alphabet. If it does, an appropriate message is displayed.
#include <iostream>
#include <string>
#include <conio>
Int main ( )
{
Char name [25];
int n;
cout<<Type your name<<endl;
cin>>n;
Last Exercise
Lab Questions
Q1. Write a program with a do-while loop that prints the numerals from
10 to 20 (inclusive), with a blank line between each number.
Solution
#include <iostream>
#include <conio>
int main ( )
Page 11 of 17
{
int z=10;
do
{
cout<<z++<<;
cout<< <<endl;
}
while ( z<=20);
getch ();
}
Q2. Write a weather-calculator program that asks for a list of the
previous 10 days temperatures, computes the average, and prints the
results. You have to compute the total as the input occurs, then divide
that total by 10 to find the average. Use a while loop for the 10
repetitions.
Solution
#include <iostream>
#include<conio>
int main ( )
{
int day=0;
float average, temp, sum=0;
while (day!=10)
{
cout<<" enter the temperature for day"<< (day+1)<<" : ";
cin>>temp;
sum+=temp;
day++;
}
average= (sum)/day;
cout<<" the average temperature for "<<day<<" days
is"<<average<<endl;
cout<<"
the
total
temperature
for
"<<day<<"days
is
"<<sum<<endl;
getch ( );
}
Q3. Rewrite the program in Exercise 2 using a do-while loop.
#include <iostream>
#include<conio>
int main ( )
{
Page 12 of 17
int day=0;
float average, temp, sum=0;
do
{
cout<<" enter the temperature for day"<<(day+1)<<endl;
cin>>temp;
sum+=temp;
day++;
}
while (day!=10);
average= (sum)/day;
cout<<"
the
average
temperature
for
"<<day<<"days
is"<<average<<endl;
cout<<"
the
total
temperature
for
"<<day<<"days
is
"<<sum<<endl;
getch ( );
}
Q4. Write a program, similar to the weather calculator in Exercise 2, but
generalize it so it computes the average of any number of days
temperatures. (Hint: You have to count the number of temperatures to
compute the final average.)
#include <iostream>
#include<conio>
int main ( )
{
int day=0;
float average, temp, sum=0;
while (day!=10)
{
cout<<" enter the temperature for day"<<(day+1)<<endl;
cin>>temp;
sum+=temp;
day++;
cout<<" the average temperature from day 1 to day "<<day<<"is
"<<(sum)/day<<endl;
}
average= (sum)/day;
cout<<" the average temperature for "<<day<<" days
is"<<average<<endl;
cout<<"
the
total
temperature
for"
<<day<<"days
is
"<<sum<<endl;
getch ( );
}
Page 13 of 17
Page 14 of 17
Page 15 of 17
Q&A for
Q 1 a.
Test 2
It tells where the program begins. The identifier main is the name of a
function. Every C++ program must have one and only one main function.
The required parentheses that follow the word main indicate that it is a
function.
b. write a program that will receive an integer number n and return the
factorial of that number to your program. The program should check if n
is 0 then it prints 1.
#include <iostream>
#include <conio>
int main()
{
int n, factor=1;
cout << "Enter an interger number: "; cin >> n;
if(n==0)
cout<<"1"<<endl;
else;
for (int j=n; j>0; j- -)
factor * = j;
cout << "Factorial is " << factor << endl;
getch ();
}
Q 2. a.
Page 16 of 17
Page 17 of 17