Pages

Saturday, January 26, 2013

Write a program , that prints all the Fibonacci numbers ,which are smaller than or equal to a number k(k≥2) ,which was entered by the user.The Fibonacci numbers are a sequence of numbers,where then-th number of Fibonacci is defined as:Fib(0)=0,Fib(1)=1,Fib(n)=Fib(n-1)+Fib(n-2) Usage :> Input of k:21 > Fibonacci numbers<=21:01123581321Solution-

#include<iostream>usingnamespacestd;intmain(void){intr=0,a=0,n,b=1,i,c;charredo;do{a=0;b=1;cout<<"enter the the value of n:";cin>>n;if(n>100){cout<<"enter some lessor value"<<endl;}else{cout<<a<<endl;for(i=0;i<=n;i++){c=a+b;a=b;b=c;cout<<"serial no."<<i+1<<"==";cout<<a<<endl;}cout<<"enter y or Y to continue:";cin>>redo;cout<<endl<<endl;}}while(redo=='y'||redo=='Y');system("pause");return0;}

Fibonacci sequence in c++
Fibonacci Series - C / C++
c++ program to generate Fibonacci series
Fibonacci numbers c++
C++ Fibonacci program
How do i write a c++ code for a fibonacci sequence
Write the program for fibonacci in c++?
C++ Program to print the Fibonacci Sequence!
Write a program to implement the Fibonacci series

Write a program that calculates the volume of a solid cone.The formula is: volume=(radius²height)/3Read in the values for the parameters height and radius(as floating point numbers).Then the program should calculate the volume considering the following restriction :radius and height must be greater than0If the user types in a nin correct value for one of the variables ,the program should print out an error message and quit.Otherwise,it displays the result.Solution-

Write a program that calculates the real solution of the quadratic equation ax²+bx+c=0Read in the values for the parameters a,b,c(type float).Then the program should calculate the solution considering the following circumstances:a=0andb=0=>Not a valid equationa=0 and b≠0 => x=-c/bb² -4ac < 0 => Not a Real Solutionb² -4ac >0 => x1= (-b+√(b² -4ac))/2a , x1= (-b -√(b² -4ac))/2aHint:The c++ function for √x is sqrt(x).To use this function you need to includemath.has a header file#include<math.h>Solution-

#include<iostream>#include<cmath>#include<cstdlib>#include<cstring>usingnamespacestd;intmain(){doublea,b,c,x1,x2;charx;cout<<"enter the value of a=";cin>>a;cout<<"enter the value of b=";cin>>b;cout<<"enter the value of c=";cin>>c;cout<<"the quadratic equation is"<<a;cout<<"*x*x+"<<b;cout<<"*x+"<<c<<endl;if(a==0&&b==0)cout<<"not a valid equation";if(a==0&&b!=0){x1=-(c/b);cout<<endl;cout<<"root="<<x1;cout<<endl;}if((b*b-4*a*c)>0){x2=(b*b)-(4*a*c);x1=-b+sqrt(x2);cout<<"root="<<x1<<endl;}if((b*b-4*a*c)<0){cout<<"not a real root"<<endl;}system("pause");return0;}

Write a C++ program that solves quadratic equation to find its roots
Write a c++ program to solve quadratic equation
C++ quadratic equation solver
Quadratic Equation: C++ Source Code
program to find the roots of a quadratic equation
C program for solving quadratic equation
How do you write a c program to solve quadratic equation

Mini-Project: Human Resource Management Program Consider that you want to write a program for the company called XYZ which produces medical instruments. This company is divided into 2 departments: Manufacturing Department (MD) and Human Resource Management department (HRM). You are requested to write a program for HRM department of company XYZ including the maximum number of 100 employees. shows main menu for your program. You are allowed to re-design this menu but with the same functionalities. Note that after each step you should come back to main menu.Welcome to Human Resource Management (HRM) Software of Company XYZ. To do specific task please choose one of the following commands.1. Add new employee2. Delete employee information3. Update employee information4. Make reports based on specific field5. Search employee6. QuitPlease enter the related number of your requested command?

You should use class definition Person (See Figure 3.2) and class definition HRM (See Figure 3.3). Note that in class Person, setting the values for all fields is not possible. You have to calculate the value for the field “Salary” after initializing the fields “WorkingHours” and “CostPerHour” by user. For those which the set function works, the validity of the entered data should be checked. For example, negative values for fields “Salary”, ”WorkingHours” and ”CostPerHour” are not accepted. As another example the field “WorkingHours” should be between 1 and 60.

Class Person should include following private fields:

 FirstName (String)

 LastName (String)

 PersonalID (Integer)

 Salary (Double)

 WorkingHours (Double)

 CostPerHour (Double)

Class Person should have public member functions for setting and getting the private fields.

Member functions should have the following naming style:

 set_FieldName()

 get_FieldName()

The field “PersonalID” of class Person should be unique and auto-increment with the initial value of 8921001 for the first employee. It means that user should not enter the value for “personalID”.Class HRM should include following private fields: Array of employees with the type Person (Private) The actual amount of staff which is stored in Array of employees(private)Class HRM should include following public member functions: AddPerson() DeletePerson(…) UpdatePerson(…) ReportList(…) SearchPerson(…)

Please note that you need to check the actual amount of employees and in case of reaching to the number 100 for the total number of employees you should give proper message. For the actual amount of employees you should not enter the value yourself and your program should calculate automatically the amount while entering or deleting the information of an employee.

Based on the description of the program, you need to define some arguments for functions DeletePerson(…), UpdatePerson(…), ReportList(…), SearchPerson(…) instead of (…).

1. AddPerson()

This function allows users to enter the related information of employees in class HRM. During the initialization step your program should get the working hours per week (e.g. 35) for the employee and the payment for his/her work per hour. Then, you should calculate the total salary for him/her per year. You should consider 52 working weeks for one year in your calculations. shows the sample output of this function.

Please enter the first name of an employee? AlexPlease enter the last name of an employee? PetersonHow many hours a week is his/her work? 35How much per hour is his/her salary? 20The employee with the following information has been added to the system:First Name Last Name Personal ID Salary per year (Euros)-------------- -------------- -------------- ---------------------------Alex Peterson 8921001 36400Do you want to add another employee (y/n)? n2. DeletePerson(…)This function allows user to delete the staff information. Since the only unique value in the list of employees is “Personal Number”, therefore delete function should be based on this field. Note that in order to enter the correct personal number of employee you need to find his/her personal ID using the function SearchPerson(…).Please enter the personal number of an employee? 2425374Sorry, there is not any employee with requested personal number. Do you want to repeat delete by entering the new personal number (y/n)? yPlease enter the personal number of an employee? 8921002Do you really want to delete employee Michael Jackson (y/n)? yThe employee Michael Jackson has been deleted. Do you want to repeat delete by entering the new personal number (y/n)? n3. UpdatePerson(…)This function allows user to make changes in some fields of staff information. The field “Personal Number” is not allowed to be changed. For example, if user wants to change the number of working hours for specific employee, he should use this function. Since the only unique value in the list of employees is “Personal Number”, therefore update function should be based on this field. You could use the Figure 3.6 as a basic idea for your development. Note that during the update process, if user changes fields “working hours” or “salary of one hour work”, you need to re-calculate yearly salary based on new values and update related fields.Please enter the personal number of an employee? 2425374Sorry, there is not the employee with requested personal number. Do you want to repeat update by entering the new personal number (y/n)? yPlease enter the personal number of an employee? 8921001Please enter the related number of field which you would like to update(1. First name, 2. Family name, 3. Working hours per week, 4. Payment for one hour)? 4Please enter new payment for one hour in Euros for Mr. Peterson? 25Do you want to update any other field (y/n)? nThe information for Mr. Peterson has been updated. Do you want to repeat update by entering the new personal number (y/n)? n

4. ReportList(…)In this function, user can choose a specific field to make reporting. These fields can be “Family Name” or “Salary”. You could use Figure 3.7 as a basic for your development. The list will be sorted ascending based on the requested field.

Please enter the related number of the field which you would like to sort the list based on it.

5. SearchPerson(…)In this function, user can find specific people using chosen fields. These fields can be “Family Name” or “Salary”. You could use Figure 3.8 as a basic for your development.By using salary as a search field, user should define minimum and maximum values for search. As a result he/she will get the list of employees who their salary is between requested Min_Salary and Max_salary. For searching the employee with specific amount of salary, user should define same Min_Salary and Max_Salary values.By using the “Family Name” as a search field user will get the list of employees who their family name is equal to requested family name.Search is based on two different fields (1.family name, 2.Salary), please enter your choice? 2

Please define your search range for salary of employees (S_min, S_max).What is minimum salary for search (S_min)? 60000What is maximum salary for search (S_max)? 110000Following is the list of employees for your defined search fields:First Name Family Name Personal Number salary (Euro)-------------- ---------------- ---------------------- ----------------Martin Klein 8921003 81900.00Sarah Müller 8921004 105300.00Do you want to do new search (y/n)? ySearch is based on two different fields (1.family name, 2.Salary), please enter your choice? 1Please enter the family name of employee? PetersonFollowing is the list of employees for your defined search fields:First Name Family Name Personal Number salary (Euro)-------------- ---------------- ---------------------- ----------------Alex Peterson 8921001 45500.00Do you want to do new search (y/n)? nSolution-

#include<iostream>#include<math.h>#include<cstdlib>#include<string>usingnamespacestd;classPerson{private:stringFirstName;// student name, max 49 charactersstringLastName;// student family nameintPersonalID;doubleSalary;doubleWorkingHours;doubleCostPerHour;public:voidset_FieldName();voidget_FieldName();voidgett_FieldName();voidset_PersonalID();voidset_Name();voidLastNamesortList();voidin_FirstName();voidin_FamilyName();voidin_Workinghour();voidin_Costperhour();};classHRM{private:Persone[100];Persontemp[100];public:voidAddPerson();voidDeletePerson();voidSearchPerson();voidUpdatePerson();voidReportList();};////global variables declaredintn=0,i=0,x=8248001,y[100];boolflag=0;intz[100];stringh[100];doublesal[100];intcheck=0;/////////////////////////////////////////////////////////////////////// Definition of the AddPerson() method of the Company class// This method will add an employee to the Company class instance. // The attributes of the employee should be those of the user's // own choosing.void::HRM::AddPerson(){intx;charredo;do{n++;e[i].set_FieldName();i++;cout<<"\nThe employee with the following information has been added to the system:"<<endl;cout<<"\nFirst Name Last Name Personal ID Salary per year (Euros)";cout<<"\n-------------- -------------- ------------ -------------------------"<<endl;//cout<<"naaaaaaaaaaaam"<< n<<endl;for(inti=0;i<n;i++){e[i].get_FieldName();}cout<<"do u wont to add another employee"<<endl;cin>>redo;}while((redo=='y'||redo=='Y'));}/////////////////////////////////////////////////////////////////////// Definition of the DeletePerson() method of the Company class.// This method will delete the employee of the user's choosing from// the Company class instance.voidHRM::DeletePerson(){// Show all of the current employees// Ask the user the ID of which employee that they wish to// delete.intempId;boollol;charredo1,redo2;lol=false;lebel:cout<<"ID of employee to remove: ";while(!(cin>>empId))//Reciving vaiables from input : is it no/character ?{cout<<"Please enter a number! Try again: ";cin.clear();cin.ignore(1000,'\n');// Skip to next newline or 1000 chars,// whichever comes first.}for(i=0;i<n;++i){if(y[i]==empId){e[i]=e[i+1];lol=true;e[i].set_Name();cin>>redo2;if(redo2=='Y'||redo2=='y'){inta;a=n;cout<<"\nThe employee with the following information has been added to the system:"<<endl;cout<<"\nFirst Name Last Name Personal ID Salary per year (Euros)";cout<<"\n-------------- -------------- ------------ -------------------------"<<endl;for(inti=0;i<a;i++){e[i].get_FieldName();cout<<"hahahahah="<<n<<endl;a--;n=a;n++;}/// goto lebel1;}cout<<endl;//Delete function}}if(lol==false){cout<<"Sorry, there is not any employee with requested personal number."<<" Do you want to repeat delete by entering the new personal number (y/n)?:";cin>>redo1;if(redo1=='Y'||redo1=='y'){gotolebel;cout<<endl<<endl;}}// Delete the chosen employee from the array of employees// as represented in this class. // Actually remove the entry from memory so as to not leak objects//nextIndex--;}/////////////////////////////////////////////////////////////////////// Definition of the UpdatePerson() method of the Company class// This method will modify an attribute of the employee in // the Company class instance. The employee and attribute should be// ones of the user's own choosing.voidHRM::UpdatePerson(){intempId;charredo1,redo2;lebel:cout<<"ID of employee to modify data: ";while(!(cin>>empId))//Reciving vaiables from input : is it no/character ?{cout<<"Please enter a number! Try again: ";cin.clear();cin.ignore(1000,'\n');// Skip to next newline or 1000 chars,// whichever comes first.}intflag1=0;for(inti=0;i<n;++i){if(y[i]!=empId){flag1++;}}/* if (flag1==n){ // cout<<" not matching="<< y[i];cout<<"Sorry, there is not any employee with requested personal number. Do you want to repeat delete by entering the new personal number (y/n)?:"; cin>>redo1; if(redo1=='Y'||redo1=='y'){ goto lebel; } } */cout<<endl;lebel1:for(inti=0;i<n;++i){if(y[i]==empId){cout<<"matching="<<y[i];flag=true;intchoice=0;charredo;do{cout<<endl<<endl;cout<<"Please enter the related number of field which you would like to update"<<endl;cout<<"1. First name"<<endl;cout<<"2. Family name"<<endl;cout<<"3. Working hours per week"<<endl;cout<<"4. Payment for one hour"<<endl;cout<<std::endl;cin>>choice;if(choice==1){cout<<" First name: ";e[i].in_FirstName();}elseif(choice==2){cout<<" Family name: ";e[i].in_FamilyName();}elseif(choice==3){cout<<" Working hours per week: ";e[i].in_Workinghour();}elseif(choice==4){cout<<" Payment for one hour: ";e[i].in_Costperhour();}cout<<"Do you want to update another field (Y/N)=";cin>>redo;}while(redo=='y'||redo=='Y');}}inta;a=n;cout<<"\nThe employee with the following information has been added to the system:"<<endl;cout<<"\nFirst Name Last Name Personal ID Salary per year (Euros)";cout<<"\n-------------- -------------- ------------ -------------------------"<<endl;for(inti=0;i<a;i++){e[i].get_FieldName();cout<<"hahahahah="<<n<<endl;}}void::Person::in_FirstName(){cin>>FirstName;}void::Person::in_FamilyName(){cin>>LastName;}void::Person::in_Workinghour(){cin>>WorkingHours;Salary=WorkingHours*CostPerHour*52;}void::Person::in_Costperhour(){cin>>CostPerHour;Salary=WorkingHours*CostPerHour*52;}voidHRM::ReportList(){charop;booldoMore;cout<<"\nPlease enter the related number of the field which you would like to sort the list based on it.\n(1. Family name, 2.Salary)?\n"<<endl;//cin>>op;while(!(cin>>op))//Reciving vaiables from input : is it no/character ?{cout<<"Please enter a number! Try again: ";cin.clear();cin.ignore(1000,'\n');// Skip to next newline or 1000 chars,// whichever comes first.}switch(op){case'1':cout<<"\nSorting based on Family Name\n"<<endl;for(inti=0;i<=n;i++){for(intj=i+1;j<=n-1;j++){if(h[i]>h[i+1]){temp[i]=e[i];e[i]=e[j];e[j]=temp[i];}}}for(inti=0;i<n;i++){e[i].get_FieldName();}cout<<"\nsorted\n";break;case'2':cout<<"\nSorting based on Salary\n"<<endl;for(inth=0;h<n;h++){for(intq=h+1;q<n;q++){if(sal[h]>sal[h+1]);{temp[h]=e[h];e[h]=e[q];e[q]=temp[h];}}}for(intj=0;j<n;j++){e[j].get_FieldName();}cout<<"\nsortedlist is printed above\n";break;}}voidHRM::SearchPerson(){intc;charredo1;stringfamilyname;doublemin,max;do{cout<<"Search is based on two different fields (1.family name, 2.Salary), please enter your choice?="<<endl;//cin>>c;while(!(cin>>c))//Reciving vaiables from input : is it no/character ?{cout<<"Please enter a number! Try again: ";cin.clear();cin.ignore(1000,'\n');// Skip to next newline or 1000 chars,// whichever comes first.}if(c==2){cout<<"Please define your search range for salary of employees ."<<endl;cout<<"What is minimum salary for search (S_min)?="<<endl;//cin>>min;while(!(cin>>min))//Reciving vaiables from input : is it no/character ?{cout<<"Please enter a number! Try again: ";cin.clear();cin.ignore(1000,'\n');// Skip to next newline or 1000 chars,// whichever comes first.}cout<<"What is maximum salary for search (S_max)?="<<endl;//cin>>max;while(!(cin>>max))//Reciving vaiables from input : is it no/character ?{cout<<"Please enter a number! Try again: ";cin.clear();cin.ignore(1000,'\n');// Skip to next newline or 1000 chars,// whichever comes first.}inta;a=n;cout<<"\nThe employee with the following information has been added to the system:"<<endl;cout<<"\nFirst Name Last Name Personal ID Salary per year (Euros)";cout<<"\n-------------- -------------- ------------ -------------------------"<<endl;for(inti=0;i<n;i++){if(z[i]>min&&z[i]<max){cout<<"naaaaaaaaaaaam"<<n<<endl;e[i].gett_FieldName();cout<<"matching="<<z[i];}}}elseif(c==1){cout<<"Please enter the family name of employee?"<<endl;cin>>familyname;cout<<"\nThe employee with the following information has been added to the system:"<<endl;cout<<"\nFirst Name Last Name Personal ID Salary per year (Euros)";cout<<"\n-------------- -------------- ------------ -------------------------"<<endl;for(inti=0;i<n;i++){if(h[i]==familyname){cout<<"naaaaaaaaaaaam"<<n<<endl;e[i].gett_FieldName();cout<<"matching="<<z[i];}}}cout<<"\nDo you want to Search any other field (y/n)?\n"<<endl;cin>>redo1;}while(redo1=='y'||redo1=='Y');}void::Person::LastNamesortList(){inttemp2;chartemp,temp1;}void::Person::set_Name(){cout<<"Do you really want to delete employee"<<FirstName<<"\t"<<LastName<<"(y/n)?:";//PersonalID=y[i];}intk=0;void::Person::set_FieldName(){PersonalID=x;x++;cout<<n;cout<<"First Name=";while(!(cin>>FirstName))//Reciving vaiables from input : is it no/character ?{cout<<"Please enter a string! Try again: ";cin.clear();cin.ignore(1000,'\n');// Skip to next newline or 1000 chars,// whichever comes first.}cout<<"Last Name=";while(!(cin>>LastName))//Reciving vaiables from input : is it no/character ?{cout<<"Please enter a string! Try again: ";cin.clear();cin.ignore(1000,'\n');// Skip to next newline or 1000 chars,// whichever comes first.}cout<<"How many hours a week is his/her work? =";;while(!(cin>>WorkingHours))//Reciving vaiables from input : is it no/character ?{cout<<"Please enter a number! Try again: ";cin.clear();cin.ignore(1000,'\n');// Skip to next newline or 1000 chars,// whichever comes first.}cout<<"How much per hour is his/her salary? =";while(!(cin>>CostPerHour))//Reciving vaiables from input : is it no/character ?{cout<<"Please enter a number! Try again: ";cin.clear();cin.ignore(1000,'\n');// Skip to next newline or 1000 chars,// whichever comes first.}Salary=WorkingHours*CostPerHour*52;z[i]=Salary;sal[i]=Salary;h[i]=LastName;y[k]=PersonalID;k++;}void::Person::get_FieldName(){cout<<FirstName<<"\t\t"<<LastName<<"\t\t\t"<<PersonalID<<"\t\t\t"<<Salary<<"\t"<<endl;}void::Person::gett_FieldName(){cout<<FirstName<<"\t\t"<<LastName<<"\t\t\t"<<PersonalID<<"\t\t\t"<<Salary<<"\t"<<endl;}intmain(){//-------defining variables and initializing them------------- HRMinfo;intc;charoperation,ch;//--------Printing my name on screen---------------- cout<<"Welcome to the program 2.1 written by Your Name"<<endl;cout<<"**************************************************************************"<<endl;cout<<endl<<endl<<endl;do{cout<<"Welcome to Human Resource Management (HRM) Software of Company XYZ.";cout<<"To do specific task please choose one of the following commands."<<endl<<endl<<endl;cout<<" 1. Add new employee"<<endl;cout<<" 2. Delete employee information"<<endl;cout<<" 3. Update employee information"<<endl;cout<<" 4. Make reports based on specific field"<<endl;cout<<" 5. Search employee"<<endl;cout<<" 6. Quit"<<endl<<endl;while(!(cin>>c))//Reciving vaiables from input : is it no/character ?{cout<<"Please enter a number! Try again: ";cin.clear();cin.ignore(1000,'\n');// Skip to next newline or 1000 chars,// whichever comes first.}switch(c){case1:cout<<"\nEnter the information of the new employee"<<endl;info.AddPerson();break;case2:info.DeletePerson();break;case3:cout<<"\nEnter an item to deletion";info.UpdatePerson();break;case4:cout<<"\nEnter an element to search";info.ReportList();break;case5:info.SearchPerson();break;default:cout<<"\nInvalid option try again";}cout<<"\ndo u want to continue";cin>>ch;}while(ch=='y'||ch=='Y');system("pause");return0;}