C++ codes needed

Thread Starter

ecjohnny

Joined Jul 16, 2005
142
Hey C++programmers out there i know this will take up some time but if you are willing to give me the codes to the following qns i would really appreciate it :D

A1.
(a) Write a program which accepts an integer from the keyboard and
prints out the corresponding number of the character "*". For
example, if the integer 5 is entered, five "*" will be printed out
by making a call to a function printstars().
Program outline:
main()
{
int num;
cout << “Enter a number : “;
cin >> num;
printstars(num);
}
( B) Using the printstars() function created above, design a program
to draw a right angled triangle using "stars". The adjacent sides
of the triangle have the same number of stars as entered on the
keyboard. For example, if the number entered is 5, the following
is displayed:
*
***
****
*****

--------------------------------------------------------------------------------
A2. Write a program that will analyse, for your class, the grades
obtained by all the students for Structured Programming. The
program will prompt the user to enter the grade for each
student. Valid grades are A, B, and C. The program calculates and
displays the total number of As, Bs and Cs. The user should be
able to enter the grades in uppercase or lowercase. You may
assume there are only 10 students in your class.
Your program must be modular. Write a function to read and
total the grades and another to print the results .
A skeleton of the program is given below:
char grade; //-- global variables
int totalA, totalB, totalC;
main()
{ ReadandTotalGrades();
DisplayTotals();
}
---------------------------------------------------------------------------
A3.
(a) Write a program, which prompts the user to enter three integer
numbers. It then finds and displays the smallest of the three
numbers.
Program outline:
main()
{
int num1, num2, num3, smallest;
cout << “Enter the first number : “;
cin >> num1;
cout << “Enter the second number : “;
cin >> num2;
cout << “Enter the third number : “;
cin >> num3;
smallest = findSmallest(num1, num2, num3);
cout << “The smallest number is : ” << smallest;
}

( B) Design two more functions, on lines similar to the function
findSmallest(), one to find the largest and another to find the
average of the three numbers.
The function prototypes are as follows:
int findLargest(int, int, int);
double findAverage(int, int, int);
-----------------------------------------
**Its about "Function"
Hopefully someone good will help this out :B
 

BladeSabre

Joined Aug 11, 2005
105
That sounds like it's your homework... isn't the idea for you to do it yourself so you can learn how to program?

Anyway, those are standard problems, and you can find the answers with a bit of Web searching.
 

Papabravo

Joined Feb 24, 2006
21,225
Like the man said, a little bit of effort an imagination are all that is required. This board has very little tolerance for folks who ask other people to do their work for them.
 

Dave

Joined Nov 17, 2003
6,969
To add to the above post, if you do not make an attempt at the questions yourself then your query will go unanswered. It is easy to help someone who has attempted a question, than just to reel off the answers.

If you want to post your workings, I'm sure someone will provide you the necessary guidance.

Dave
 

chesart1

Joined Jan 23, 2006
269
Hi ecJohnny,

In order to write the program for the problems you describe you must first design the algorithm. I don't know how far you are in your course, but here is an example. I am writing the program in english as you should at first.

A1.
(a) Write a program which accepts an integer from the keyboard and
prints out the corresponding number of the character "*". For
example, if the integer 5 is entered, five "*" will be printed out
by making a call to a function printstars().

Program outline:
main()
{
int num;
cout << “Enter a number : “;
cin >> num;
printstars(num);
}


English algorithm
Request an integer
Fetch the integer from the keyboard.
Call printstar
End

Printstar Procedure
Use the integer as a counter
2: print a star
decrement the integer.
if integer is not zero, go to 2
return to main.


After defining the algorithm in english, you simply translate each english step into a C++ instruction.

If you are majoring in Computer Science then it is extremely important that you practice creating algorithms to solve problems like the ones you presented in your message. This is exactly what you will be expected to do on the job.

John Mario ...
 
Top