How to write a Pseudo code for a C++ application?

closed account (iyRG3TCk)
How to write a pseudo code for C++ application like this,

#include <iostream>

using namespace std;

//Inputs
char input;

//structures.
struct customer
{
char firstname[10];
char lastname[10];
int age;
char Gender[2];

};

//Menues
void mainmenu();
void registercus();
void updatecus();
void viewcus();
void viewallcus();
void unregistercus();
void applylone();
void exit();
int searchnic(int num);

//arrays.
int nic[5] = { 0,0,0,0,0 };


void main()//using switch to choose the sub menu.
{

mainmenu();
cin >> input;


switch (input)
{
case '1':
registercus();
break;

case '2':
updatecus();
break;

case '3':
viewcus();
break;

case '4':
viewallcus();
break;

case '5':
unregistercus();
break;

case '6':
applylone();
break;

case '7':
exit();
break;

default:
cout << "Invalid Input.Check your input and try again \a" << endl;
}
getchar();
getchar();
getchar();

}

void mainmenu()
{
cout << "========== WELLCOME TO BANK OF CEYLON =========" << endl;


cout << "1) Register Customer" << endl;
cout << "2) Update Customer" << endl;
cout << "3) View Customer" << endl;
cout << "4) View All Customers" << endl;
cout << "5) Unregister Customer" << endl;
cout << "6) Apply For A Lone" << endl;
cout << "7) Exit From The Manue" << endl;


cout << "\nChoose the sub menue you want to select:" << endl;

}

void registercus()
{
int num;
cout << "You Have Selected Register Customer" << endl;


cout << "\nEnter the NIC number: ";
for (int j = 0; j < 5; ++j) {
cin >> num;

//get the vlue to a normal integer variable
//pass that value to the search
int result= searchnic(num);

if (result >= 0)
{
cout << "This ID number is already exist." << endl;
}
else
{
cout << "The ID number is not in the data base. " << endl;

}
}

customer cust;
cout << "Enter the first name: ";
cin >> cust.firstname;
cout << "Enter the last name: ";
cin >> cust.lastname;
cout << "Enter the age: ";
cin >> cust.age;
cout << "Enter the gender: ";
cin >> cust.Gender;


cout << "\nUpdate details\n" << endl;
cout << "First name: " << cust.firstname << endl << "Last name: " << cust.lastname << endl
<< "age: " << cust.age << endl << "Gender: " << cust.Gender << endl;






}

void updatecus()
{
cout << "You Have Selected Update Customer" << endl;
}

void viewcus()
{
cout << "You Have Selected View Customer" << endl;
}

void viewallcus()
{
cout << "You Have Selected View All Customers" << endl;
}

void unregistercus()
{
cout << "You Have Selected Unegister Customer" << endl;
}

void applylone()
{
cout << "You Have Selected Apply For A Lone" << endl;
}

int searchnic(int num)
{
for (int i=0; i < 5; ++i) {
if (nic[i] == num) {

return 1;


}
else {

return -1;




}

}



return 0;

}

void exit()
{

}
Hello Gimnath Priyadarshana,

I would consider this more of an outline than pseudo-code. I am not that good with writing pseudo-code, but you might want to check these links:
https://www.google.com/search?safe=strict&q=How+to+write+a+Pseudocode+for+a+C%2B%2B+application&oq=How+to+write+a+Pseudocode+for+a+C%2B%2B+application&gs_l=psy-ab.12...91386.91386.0.95496.1.1.0.0.0.0.111.111.0j1.1.0....0...1.1.64.psy-ab..0.0.0.IF32vYLFD6M

http://www.dreamincode.net/forums/topic/251429-writing-pseudo-code-tips/

Some things I noticed thatwould improve your program:

Include header file "string" and write your struct more like this:

1
2
3
4
5
6
7
struct customer
{
	std::string firstname;
	std::string lastname;
	int age;
	char Gender;  // ,<--- just needs to be a single char.
};


Using std::string will allow the first and last names to be any size that is needed. Or I would change the size of the array to 15, 20 or 25. Also I would use std::getline() to input the names because "std::cin >>" will iput to the first white space or a "\n" which ever comes first, so you could loose part of a name.

int nic[5] = { 0,0,0,0,0 }; can easily be written as: int nic[5]{ 0 }; which will initialize the entire array to zeros.

void main() should be written as int main().

After that some of the functions just need to be completed to have a working program.

Hope that helps,

Andy
Last edited on
pseudo code ... some places have a standard for it, others just make it up, but generally you want to get rid of language details like cout << becomes print() or std::blah becomes blah and for loops might be simpler such as for i = 1 to 10 etc.

I find it really hard to write p-code for classes and OOP. There are too many things you have to think about that are too ingrained in the language.
Last edited on
write the Pseudo code first. If you don't then you should damn sure use comments, unlike your example. Using good comments, you can just print the comments and use that for pseudo code.

Make it like a flow chart

program start
Do something
get user input
if y
Do again
if n
program end

closed account (iyRG3TCk)
#Handy Andy
#Jonnin
#SamuelAdams

Thnx friends..Actually u did a great help. XD
closed account (iyRG3TCk)
Guyz thnx all.. U guyz did a really great help for me..
and Handy Andy thnx for the feed back..I will improve my programming as u said thnx again .XD
Topic archived. No new replies allowed.