Software-help

Software-help Page for IT students

13/04/2016

// Inheritance code
// A Person class is created with 2 data members (access specifier is protected not private)
// A Student class is created with 2 data members and it inherits Person class
// So all public & protected data members are accessible in Student class.


using namespace std;

class Person{
protected:
string name;
char gender;

public:
Person()
{
name = "";
gender = ' ';
}

Person(string t_name, char t_gender)
{
name = t_name;
gender = t_gender;
}

void set_Person(string t_name, char t_gender)
{
name = t_name;
gender = t_gender;
}

string get_name()
{
return name;
}

char get_gender()
{
return gender;
}
};

class Student : public Person{
private:
int std_id;
string std_degree;
public:
Student()
{
std_id = 0;
std_degree = "";
}

Student(int t_sid, string t_s_degree)
{
std_id = t_sid;
std_degree = t_s_degree;
}

void set_Student(int t_sid, string t_s_degree)
{
std_id = t_sid;
std_degree = t_s_degree;
}

int get_std_id()
{
return std_id;
}

string get_std_degree()
{
return std_degree;
}

};

int main()
{

// In main 2 different Person objects are created and displayed.
Person p1;
p1.set_Person("Zahid", 'M');

Person p2("Ayesha", 'F');

cout

13/04/2016


using namespace std;
class Distance
{
private:
int feet;
float inches;
public:
// Constructor with declaration & definition
Distance()
{
feet = 0;
inches= 0;
}

void set_All(int , float); // 1 Setter with declaration only. Definition is seperate

int get_feet(); // 2 Getters with declaration only. Definition is seperate
float get_inches();

Distance operator + (Distance); // Operator Overloading
void operator += (Distance); // Operator Overloading

}; // End of class

/* Seperate definitions of each member function. Rule is

function_return_type Class_name :: function_name( arguments )
{
function definition
}
*/
Distance Distance::operator + (Distance t_d2)
{
Distance tmp;
tmp.feet = feet + t_d2.feet;
tmp.inches = inches + t_d2.inches;

return tmp;
}

void Distance::operator += (Distance t_d2)
{
feet = feet + t_d2.feet;
inches = inches + t_d2.inches;
}

void Distance::set_All(int t_feet, float t_inches)
{
feet = t_feet;
inches = t_inches;
}
int Distance::get_feet()
{
return feet;
}
float Distance::get_inches(){
return inches;
}

int main()
{
Distance d1;
d1.set_All(10,2.8);

Distance d2;
d2.set_All(4, 5.6);

cout

08/03/2016

//Author: Qaisar Abbas Khokhar



using namespace std;
struct node1
{
int data1;
node1 *next1;
}
*top1 = NULL,
*p1 = NULL,
*np1 = NULL;

struct node2
{
int data2;
node2 *next2;
}
*top2 = NULL,
*p2 = NULL,
*np2 = NULL;

struct node3
{
int data3;
node3 *next3;
}
*top3 = NULL,
*p3 = NULL,
*np3 = NULL;

void push1(int data)
{
np1 = new node1;
np1->data1 = data;
np1->next1 = NULL;
if (top1 == NULL)
{
top1 = np1;
}
else
{
np1->next1 = top1;
top1 = np1;
}
}

int pop1()
{
int b = 999;
if (top1 == NULL)
{
return b;
}
else
{
p1 = top1;
top1 = top1->next1;
return(p1->data1);
delete(p1);
}
}

void push2(int data)
{
np2 = new node2;
np2->data2 = data;
np2->next2 = NULL;
if (top2 == NULL)
{
top2 = np2;
}
else
{
np2->next2 = top2;
top2 = np2;
}
}

int pop2()
{
int b = 999;
if (top2 == NULL)
{
return b;
}
else
{
p2 = top2;
top2 = top2->next2;
return(p2->data2);
delete(p2);
}
}

void push3(int data)
{
np3 = new node3;
np3->data3 = data;
np3->next3 = NULL;
if (top3 == NULL)
{
top3 = np3;
}
else
{
np3->next3 = top3;
top3 = np3;
}
}

int pop3()
{
int b = 999;
if (top3 == NULL)
{
return b;
}
else
{
p3 = top3;
top3 = top3->next3;
return(p3->data3);
delete(p3);
}
}

int top_of_stack()
{
if (top1 != NULL && top1->data1 == 1 )
{
return 1;
}
else if (top2 != NULL && top2->data2 == 1)
{
return 2;
}
else if (top3 != NULL && top3->data3 == 1)
{
return 3;
}
}

void display1()
{
cout

07/01/2016

/*
Copyright:
**********
This program code can be used, alter, distributed in any positive way
Author:
*******
Qaisar Abbas
*/
//First Creat txt file with name "data.txt"
/*****************************************************
# Authors Qaisar Abbas
*******************************************************/




using namespace std;
struct node
{
string name;
string number;
node*next;
};
//Declear Global Variable
node *head=NULL;
int count=0;
//Start of Function Declaration
void getDataFromFile();
void addNumber(string, string);
void searchNumber();
void saveDataInFile();
int runagain();
//Start of Main Function
int main()
{
//Start of Local Declaration
string fname;
string no;
int run;
int optn;
//End Of Local Declaration

//Function Call To Get data from file
getDataFromFile();

//Start do while loop to Run Program again
do{
//Start of User Menu
coutnext=NULL;
}
else
{
node *temp;
temp=new node();
temp->name=fname;
temp->number=no;
node *crnt=head;
while(crnt->next!=NULL)
{
crnt=crnt->next;
}
crnt->next=temp;
temp->next=NULL;
}
}//End Of function Defination

//Start of Function Search Number Defination
void searchNumber()
{
string key;

coutkey;
node *crnt=head;
while(crnt!=NULL)
{
if(crnt->name==key)
{
cout

25/11/2015

Game in C++
//Author ALI NUMAN GILANI
*********************************************
/*
Copyright:
**********
This program code can be used, alter, distributed in any positive way

Author:
*******
ALI NAUMAN GILANI
ASST. PROF. CS&IT DEPARTMENT
SUPERIOR UNIVERSITY,
LAHORE, PAKISTAN

Date of Creation:
*****************
9th May, 2011

Date of modifications (if any):
*******************************
9th May, 2011

Program Description:
********************
-> Its two player game\n"
-> Initially there are 10 balls\n"
-> Players will pick ball(s) turn by turn\n"
-> Each player can pick 1 or 2 balls maximum in each turn\n"
-> Player who will finish the balls in his/her turn will win the game\n"

Comments about program:
***********************

*/

//header file inclusions



//using standard namespace
using namespace std ;

//start of main function
int main ( )
{
//*************************************************************************//
//local declarations
int player , //variable to store player 1 or 2
playerSelectionChoice , //variable to selsct player 1 or 2 for first turn
noOfBalls = 10 , //variable to store total number of balls ( initially 10 balls)
noOfBallsPicked , //variable to store no of balls picked by player in each turn ( 1 or 2 max)
gameWinningFlag ; //Indicator for game winning for player 1 or 2

char programContinuationChoice ; //variable to store choice for program continuation
//end of local declarations
//*************************************************************************//

//information about the game
cout

Baby Run simple programcout
25/11/2015

Baby Run simple program
cout

Kon Kon yeh feel kerta hay???
25/11/2015

Kon Kon yeh feel kerta hay???

25/11/2015

//Author: David Riggleman
See Project:....
//*****************************************************************************
//File Name: main.cpp
//
//Summary: this program reads in a list of numbers from a file, computes, the
// mean, finds the min/max, sorts the list, and the prints to the screen and
// then writes to an output file
//
//Author: David Riggleman
//Created: 13 January 2009
//*****************************************************************************

//needse

//used for external file input and output

using namespace std;

//******************** Input/Output Functions *******************************

int inputFromFile(int list[]);
//precondition: the function reads in a list of numbers from a file which will
// be specified by the user. The first number of the list must be used to
// to indicate the number of items in the list. In additino, the function
// must be passed an empty array
//postcondition: the list of numbers from the input file will be stored in the
// array and the number of items (the array size) will be returned

void outputToStream(double mean, int min, int max, const int list[],
int arraySize, ostream& outputStream);
//precondition: if writing to an external file, outputStream must already have
// been opened
//postcondition: the function ouputs the results to an output stream, either to
// the screen or to an output file

void initializeFileOutput(ofstream& fout);
//postcondition: the function asks the user to name the output file and then
// opens the output file stream.

//******************** Computational Functions ********************************

double computeMean (const int list[], int arraySize);
//postcondition: the funciton calculates the mean given a list of numbers and
// the number of items in the list.

int findExtreme(const int list[], int arraySize, bool isMax);
//precondition: the boolean variable end determines whether the function will
// return either the max or min. If end = 0 (low), the minimum will be returned
// and if end = 1 (high), the maximum will be returned
//postcondition: the function returns the extreme specified by the boolean
// paramater (either a min or max)

//*********************** Sorting Functions **********************************

void sort (int list[], int arraySize);
//postcondition: the items in the array are sorted using a selection sort

void swapValues(int& number1, int& number2);
//postcondition: the function swaps the values of the two integers passed to
// this function

int main(int argc, char *argv[])
{
const int MAX_ARRAY_SIZE = 1000;
int numberedList[MAX_ARRAY_SIZE];
int arraySize = inputFromFile(numberedList);
double mean = computeMean(numberedList, arraySize);
int minimum = findExtreme(numberedList, arraySize, 0);
int maximum = findExtreme(numberedList, arraySize, 1);
sort(numberedList,arraySize);
ofstream fout;
initializeFileOutput(fout);
outputToStream(mean, minimum , maximum, numberedList, arraySize, cout);
outputToStream(mean, minimum , maximum, numberedList, arraySize, fout);
fout.close();
system("PAUSE");
return EXIT_SUCCESS;
}

//******************** Input/Output Functions *******************************

int inputFromFile(int list[])
{
int arraySize = 0;
char inputFile[32];
cout > inputFile;
ifstream fin;
fin.open(inputFile);
if(fin.fail()) //checks that the input file opened successfully
{
cout > list[counter];
}
fin.close();
return arraySize;
}

void outputToStream(double mean,int min,int max,
const int list[], int arraySize, ostream& outputStream)
{
outputStream

22/11/2015

Class work.
**************************************************
//Author :Qaisar Abbas Khokhar Bharmi


using namespace std;

struct node
{
int data;
node *next;
};
node*head=NULL;
void dell();
void addNode(int);
void print();
int main()
{
for(int i=1;idata=x;
head->next=NULL;
}

else
{

node *temp;

temp= new node();

temp->data=x;

node *cur=head;

while(cur->next!=NULL)
{
cur=cur->next;

}

cur->next=temp;

temp->next=NULL;

}
}
void dell()
{
cout

22/11/2015

Single link list
*********************************************
//Author : Qaisar Abbas Khokhar Bharmi


using namespace std;
struct bharmi
{
int num;
bharmi *next;
};
bharmi *head=NULL;
void addData(int);
void printData();
int main()
{

int a,b;
coutb;
for(int i=1;inext;
}

crnt->next=temp;
temp->next=NULL;
}

}

void printData()
{
cout

Address

Lahore

Website

Alerts

Be the first to know and let us send you an email when Software-help posts news and promotions. Your email address will not be used for any other purpose, and you can unsubscribe at any time.

Share