Trouble with Pseudo code

Hi this is my first post on here I am taking c++ in college and I am having trouble reading pseudo code by our professor. I just really have no idea how to do this program but its supposed to be easy once you have the pseudo code correct? Also is there a program that you would reccomend to develop on for Mac?

The program is supposed to take values from a txt file and use it solve for the roots of a quadratic equation.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  Function main () Returns 0 on success
Open "coeffs.txt" for reading using a defined ifstream object named fin
a ← ReadCoeff ( fin )
b ← ReadCoeff ( fin )
c ← ReadCoeff ( fin )
Close fin
root1 ← CalcRoot1 ( a, b, c )
root2 ← CalcRoot1 ( a, b, c )
Output ( a, b, c, root1, root2 )
Return 0
End Function main
Function ReadCoeff ( fin is ifstream& ) Returns the coefficient as double
Read from fin into defined double variable coeff
Return coeff
End Function ReadCoeff
Function Discriminant ( a is double, b is double, c is double ) Returns the discriminant as double
Return b
2 ‒ 4ac
End Function
Function CalcRoot1 ( a is double, b is double, c is double ) Returns root1 as double
Return ‒b + sqrt ( Discriminant ( a, b, c ))
End Function
Function CalcRoot2 ( a is double, b is double, c is double ) Returns root2 as double
Return ‒b - sqrt ( Discriminant ( a, b, c ))
End Function
Function Output( a is double, b is double, c is double, root1 is double, root2 is double ) Returns nothing
Open "roots".txt for writing using a defined ofstream object named fout
Configure fout so real numbers are displayed with five digits after the decimal point
Write to fout "The equation " a " x^2 + " b " x + " c " = 0 has roots " root1 " and " root2
Close fout
End Function
Try properly indenting the "pseudo-code" first - your professor has effectively given you a complete C++ program just with different syntax.
Last edited on
It is indeed a simple program.

By the way, there is a typo in line 8.

What is it that you need help with?

As for an IDE, try Xcode: https://developer.apple.com/technologies/tools/
I use vi editor and Clang compiler from terminal,
to use Clang from terminal -command line,
you have to download and install "command line tools for xcode",
from apple's developers page.
You can see an example of how to use vi+Clang compiler in my personal web site.
-see my user profile
Last edited on
pseudocode is a language that falls somewhere between English and a formal programming language, here's an example if i want to make a million dollars:

If you can think of a new and useful product
then that's your product
otherwise
repackage an existing product as your product
make an infomercial about your product
show the infomercial on TV
charge 100$ per unit of your product
sell 10,000 units of your product


point of a pseudocode is that everyone even non-programmers must at least understand it, the first 4 lines resemble an if and else clause, and that's intentional.
but your programming plan might not be finished after only one draft, so i will use the 'stepwise refinement' technique to make it 'more detailed' such as:
take a step from my master plan to make a million dollars:

create an infomercial about your product

this might seem like too vague of a task. How do you create an infomercial? Using stepwise refiement, you can break down the single step into several others, so it becomes:

Write a script for an infomercial about your product
rent a TV studio for one day
Hire a production Crew
Hire an enthusiastic audience
Film the infomercial


there, now a part of the pseudocode has been thoroughly refined, hope this gave you an idea or something, good luck.
Last edited on
I don't know how to open the coeffs.txt or store the values after to a,b,c. I also cannot figure out how to make the coeffs.txt on qt creator which is what I am using. I tried xcode and found it more complicated. Also am I supposed to code all the other functions first before doing the main?

For example for this function ReadCoeff would it go like this? How about Discriminant?

1
2
3
4
5
6
7
8
9
10
double ReadCoeff(ifstream&)
{
double Coeff = ifstream&;
return Coeff;
}

double Discriminant(double a, double b, double c)
{
return (b*b) - (4*a*c);
}


Topic archived. No new replies allowed.