Monday, 25 November 2019

C++ Temperature Program

Temperature Program , Enter values to print following Statements
1. Less than zero print Cold
2. between 1 - 20 print normal
3. between 21 to 30 print moderate
4. between 31 to 40 print hot
5. greater than 40 print very hot



#include <iostream>
int main()
{
int temp;
std::cout<<"Menu\nWeather Program\n";
std::cout<<"Please enter temperature value between -n to +n \n";
std::cin>>temp;
if(temp<1)
std::cout<<"\nCold";
else if(temp>1 && temp<20)
std::cout<<"Normal";
else if(temp>20 && temp<30)
std::cout<<"Moderate";
else if(temp>30 && temp<40)
std::cout<<"Hot";
else
std::cout<<"Very Hot";
return 0;
}

Output

Tuesday, 17 July 2018

C++ Car Parking Management System Complete Project Source Code

C++ Car Parking Management System

This code is written by me (c) all rights are reserved, you need permission for 3rd party content use. in C++ using following components are used
a) structure
b) call by value functions
c) selection statement
d) loops

No part of this code is copied, after huge demand of this Car parking system on google search
i basically go through my previous posted project (Basic C++ car Parking Program) where i wrote simple basic car parking code
which is very basic for any one to understand. Now i used advance logics behind system to make
this project look very realistic so i added more features in this project

you are asked to enter 5 car information because only 5 slots are available for this system
if all slots are occupied you can't add new car in parking system, if any car is exit from the system than new car can be added in system. This system can calculate bill on basis of hours car is parked.
You can also see overall history of system log with full detail. You can edit occupied car on slot information by updating hours, name , phone number. You can check how many cars are occupied and how many slots are free currently in system.


following menu options are available

1 Add Your Car
2 Exit Remove Your Car
3 Bill of Parking Car
4 View All Parked Cars Information
5 Parking Slots Available
6 History/Log
7 Edit Parking Info

-------------------------------------------------------------------------------------------------------------------
Output:-


Code:-

Note:- name , phone number with dollar is concatenated because  cin.getline(variable,sizeof(variable),character used to end variable/finish name etc) is used demands example :- variable is name/phone number you want to entersizeofvariable is you want to limit the size of name/phonenumberendcharacter is used to stop wastage of useless space characters or usage of memory so i usedcin.getline(name,15,'$'); $ sign shows end of characterwhich means i enter "umarjaved" at end i need '$' to write otherwise name will not end and i am bound to enter at maximum 15 character for name only

#include<iostream>
#include<conio.h>
using namespace std;
int parking_space = 0;
int rate = 3;
int parking_hist = 0;

struct infos
{
 char name[15];
 char phone[12];
 int Park_slot;
 float hours;
};

struct his_info{
 char name[15];
 char phone[12];
 int Park_slot;
 float hours;
 float amount;
};


infos park_info[5];
his_info hist[99];

//initialization of every single function availble in program
void insert_car();
void exit_car();
void View_allInfos();
void history_infos();
void view_historyParkingInfos();
void update_parkingLog();

void main()
{
cout<<"-----Menu-----"<<endl;
cout<<"----1 Park Your Car----"<<endl;
cout<<"----2 Exit Your Car----"<<endl;
cout<<"----3 Rate of Parking Car----"<<endl;
cout<<"----4 View All Parked Cars Information----"<<endl;
cout<<"----5 Parking Slots Available----"<<endl;
cout<<"----6 History/Log ----"<<endl;
cout<<"----7 Edit Parking Info----"<<endl;
int choice;
cin>>choice;
do
{

switch(choice)
{
case 1:
{
insert_car();
break;
}
case 2:
{
exit_car();
break;
}
case 3:
{
cout<<endl<<"-------------(Info)---------------------------"<<endl<<endl;
cout<<"3 dollars Per Hour"<<endl;
cout<<endl<<"-------------(Info)---------------------------"<<endl<<endl;
break;
}
case 4:
{
View_allInfos();
break;
}
case 5:
{
cout<<endl<<"-------------(Info)---------------------------"<<endl<<endl;
cout<<"Space Slot Total Available = "<<5-parking_space<<endl;
cout<<endl<<"-------------(Info)---------------------------"<<endl<<endl;
break;
}
case 6:
{
view_historyParkingInfos();
break;
}
default:
{
update_parkingLog();
break;
}
}

cout<<"-----Menu-----"<<endl;
cout<<"----1 Park Your Car----"<<endl;
cout<<"----2 Exit Your Car----"<<endl;
cout<<"----3 Rate of Parking Car----"<<endl;
cout<<"----4 View All Parked Cars Information----"<<endl;
cout<<"----5 Parking Slots Available----"<<endl;
cout<<"----6 History/Log ----"<<endl;
cout<<"----7 Edit Parking Info----"<<endl;

cin>>choice;
}while(1);
_getch();

}


void insert_car()
{

    cout<<"Car parking Management System"<<endl;
cout<<"Please Remember rate per hour is "<<rate<<"$"<<endl;

cout<<endl<<"-------------Info---------------------------"<<endl<<endl;
cout<<"for how many hours you want to park your car : ";
cout<<endl<<"-------------Info---------------------------"<<endl<<endl;
cin>>park_info[parking_space].hours;


if(park_info[parking_space].hours<1)
{
cout<<endl<<"-------------ERROR---------------------------"<<endl<<endl;
cout<<"Please enter valid hours and try again"<<endl;
cout<<endl<<"-------------ERROR---------------------------"<<endl<<endl;
insert_car();
}

cout<<endl<<"-------------Info---------------------------"<<endl<<endl;
cout<<"Please Pay bill of amount total = "<<rate*park_info[parking_space].hours<<endl;
float bill =0;
cout<<"Pay : ? ";
cin>>bill;
cout<<endl<<"-------------Info---------------------------"<<endl<<endl;

if(bill<rate*park_info[parking_space].hours)
{
cout<<endl<<"-------------ERROR---------------------------"<<endl<<endl;
cout<<"Please enter valid bill amount and try again"<<endl;
cout<<endl<<"-------------ERROR---------------------------"<<endl<<endl;
insert_car();
}
else if(bill>rate*park_info[parking_space].hours)
{
cout<<"Please recieve balance amount : "<<bill - rate*park_info[parking_space].hours<<endl;
}
else
{

}


//add new vehicle owner information to fill the parking slot ticket is currently processing for purchasing
cout<<"Please provide your name : "<<endl;
cin.getline(park_info[parking_space].name,15,'$');
cout<<"Please provide your cell no : "<<endl;
cin.getline(park_info[parking_space].phone,15,'$');
park_info[parking_space].Park_slot = parking_space+1;

cout<<"please park your car at parking slot number :"<<park_info[parking_space].Park_slot;


//copy all new info to history logs as well
history_infos();

parking_space++;
//parking_space++;
}



void exit_car()
{
cout<<"If you wish to remove car from parking slot press Y for Yes and N for No : "<<endl;
char cho;
cin>>cho;
if(cho == 'Y' || cho == 'y')
{
int slot;
cout<<"please enter slot # :"<<endl;
cin>>slot;

int del = 0;
//verifying car is available in slot that is mentioned by operator
for(int j=0;j<=parking_space;j++)
{
if(slot == park_info[j].Park_slot)
{
del = j;
break;
}
}


//swap next values inside the old slots
char *name[15];
char *phn[15];
int slot_pos = 0;

for(int k=del;k<parking_space;k++)
{

if(k==parking_space)
{
strcpy(park_info[k+1].name,'\0');

strcpy(park_info[k+1].phone,'\0');

park_info[k+1].Park_slot = '\0';
break;
}

//if(k<parking_space)
{
strcpy(park_info[k].name,park_info[k+1].name);
//*park_info[k].name  = *park_info[k+1].name;

strcpy(park_info[k].phone,park_info[k+1].phone);
//*park_info[k].phone = *park_info[k+1].phone;

slot_pos = park_info[k+1].Park_slot;
park_info[k].Park_slot = slot_pos-1;
}
}


//program must control or divert & stop the negative value of global variable

if(parking_space > 0)
{
parking_space--;
}

}
else
{

}
}


void View_allInfos()
{
if(parking_space == 0)
{
cout<<endl<<"-------------Info---------------------------"<<endl<<endl;
cout<<"All Slots are Available no Car is Parked right now"<<endl;
cout<<endl<<"-------------Info---------------------------"<<endl<<endl;

return;
}
else
{
cout<<endl<<"-------------Info---------------------------"<<endl<<endl;
for(int i=0;i<parking_space;i++)
{
cout<<endl<<endl;

cout<<"name : "<<park_info[i].name<<endl;
cout<<"cell no : "<<park_info[i].phone<<endl;
cout<<"Slot number :"<<park_info[i].Park_slot<<endl;
cout<<"Hours Allocated for Parking :"<<park_info[i].hours<<endl;
cout<<"Amount Paid for Parking :"<<park_info[i].hours*rate<<endl;
}
cout<<endl<<"-------------Info---------------------------"<<endl<<endl;
}
}


void history_infos()
{
strcpy(hist[parking_hist].name,park_info[parking_space].name);
strcpy(hist[parking_hist].phone,park_info[parking_space].phone);
hist[parking_hist].Park_slot = park_info[parking_space].Park_slot;
hist[parking_hist].hours=park_info[parking_space].hours;
hist[parking_hist].amount = park_info[parking_space].hours * rate;
parking_hist++;
}


void view_historyParkingInfos()
{
if(parking_hist == 0)
{
cout<<endl<<"-------------Info---------------------------"<<endl<<endl;
cout<<"In history no Car is Parked right now"<<endl;
cout<<endl<<"-------------Info---------------------------"<<endl<<endl;

return;
}
else
{

cout<<endl<<"-------------(Info)---------------------------"<<endl<<endl;
for(int i=0;i<parking_hist;i++)
{
cout<<endl<<endl;
cout<<"name : "<<hist[i].name<<endl;
cout<<"cell no : "<<hist[i].phone<<endl;
cout<<"Slot number :"<<hist[i].Park_slot<<endl;
cout<<"Hours Parked : "<<hist[i].hours<<endl;
cout<<"Amount Bill : "<<hist[i].amount<<endl;
}
cout<<endl<<"-------------(Info)---------------------------"<<endl<<endl;
}


}


void update_parkingLog()
{

if(parking_space == 0)
{
cout<<endl<<"-------------Info---------------------------"<<endl<<endl;
cout<<"Empty no Slot information found to update/edit"<<endl;
cout<<endl<<"-------------Info---------------------------"<<endl<<endl;

return;
}
else
{


char name[15];
char phns[15];
int hr;

int slot;
cout<<"Enter Slot Number Please : ";
cin>>slot;
for(int i =0;i<parking_space;i++)
{
if(slot == park_info[i].Park_slot)
{
cout<<endl<<"Enter Name = "; cin.getline(name,15,'$');
cout<<endl<<"Enter Phone = "; cin.getline(phns,15,'$');
cout<<endl<<"Enter Parking Hours = "; cin>>hr;
strcpy(park_info[i].name,name);
strcpy(park_info[i].phone,phns);
park_info[i].hours = hr;
cout<<endl<<"-------------Info---------------------------"<<endl<<endl;
cout<<"Successfully Modified Information"<<endl;
cout<<endl<<"-------------Info---------------------------"<<endl<<endl;

break;
}

}
}

}



Monday, 16 July 2018

C++ Enter full name and Count all characters in name

C++ program
User need to enter first name , last name in C++ program, the name length will be calculated for each character later output will be displayed on screen
first name : umar$
last name : javed$
Note: what is $ this symbol i wrote in code to remind program that its end of character for name

Output


code : //programmingisbest.blogspot.com

  1. #include<iostream>
  2. #include<conio.h>
  3. using namespace std;
  4. //programmingisbest.blogspot.com
  5. void main()
  6. {//programmingisbest.blogspot.com
  7. char fname[15],lname[15];
  8. cout<<"\nYour first name please : ";
  9. cin.getline(fname,15,'$');//programmingisbest.blogspot.com
  10. cout<<"\nEnter your last name please : ";
  11. cin.getline(lname,15,'$'); //programmingisbest.blogspot.com
  12. //cout<<"\n\n YourName : "<<fname<<" "<<lname;
  13. int counter = 0;//programmingisbest.blogspot.com
  14. char ch='a';//programmingisbest.blogspot.com
  15. int flag = 0;//programmingisbest.blogspot.com
  16. int loop = 1;//programmingisbest.blogspot.com
  17. while(ch<='z')
  18. {//programmingisbest.blogspot.com
  19. if(flag ==0)
  20. {//programmingisbest.blogspot.com
  21. if(ch == fname[counter])
  22. {//programmingisbest.blogspot.com
  23. counter++;
  24. ch='a';
  25. }
  26. else
  27. {//programmingisbest.blogspot.com
  28. ch++;
  29. if(fname[counter] =='\0')
  30. {//programmingisbest.blogspot.com
  31. flag = 1;
  32. ch='a';
  33. }
  34. }

  35. }//programmingisbest.blogspot.com
  36. else
  37. {
  38. if(ch == lname[loop])
  39. {
  40. counter++;
  41. loop++;
  42. ch='a';
  43. }
  44. else
  45. {//programmingisbest.blogspot.com
  46. ch++;
  47. } //programmingisbest.blogspot.com
  48. } //programmingisbest.blogspot.com
  49. }//programmingisbest.blogspot.com
  50. cout<<"\nCounted characters in whole name are : "<<counter;
  51. _getch(); //programmingisbest.blogspot.com
  52. }//programmingisbest.blogspot.com


Tuesday, 4 October 2016

C++ OOP write a program to input a date print on the screen by using class

Code:-


#include<iostream>
#include<conio.h>
using namespace std;

class Time{
private:
int hour;
int minute;
int seconds;
public:
int flag = 0;

void get_Time(){
if (flag == 0)
{
cout << "Enter time Please _:_:_";
flag = 1;
}
if (flag == 1)
{
cin >> hour;
if (hour < 24)
{
flag = 2;
cout << "hours is finished";
}
else
{
flag = 1;
get_Time();
}
}
if (flag == 2)
{
cin >> minute;
if (minute <= 60)
{
flag = 3;

cout << "minute is finished";
}
else
{
flag = 2;
get_Time();
}
}
if (flag == 3)
{
cin >> seconds;
if (seconds <= 60)
{
flag = 4;

cout << "seconds is finished";
}
else
{
flag = 3;
get_Time();
}
}
}

void set_Time(){
cout << "Time is " << hour << ":" << minute << ":" << seconds;
}
};

void main()
{
Time tC;
tC.get_Time();
tC.set_Time();

_getch();
}


output:-


Thursday, 29 September 2016

C++ Convert 4 character plain text to cypher text

Always remember to get desired output from machine you have to first provide significant solutions to respective problems so i proposed following option

first thing is very important to create algo & implement Algo in any language . I don't want to discuss in depth but main purpose of this program is to accomplish basic working of simple text(such as string) to cypher(desired alphabates encryption) its not efficient algo but i have written for poor programmers. You know copy paste programmers are qualified professional degree holder but behind the scene they are nothing more than copy paste so i suggest my students , followers don't learn programming by heart just give some precious honour time for it which leads you to get huge grip in easly making of logical solution for simple programs but perform logical problems that are part of programming . every one can write Code
with perfect logic & unsatisfactory logic can leads to time waste results


 have lack of interest in programming they just want to get basic idea behind the logic.


i initialized & declared character Array of 4 size.
use loop to get single character in each array index
the key_size is used to apply on each character to apply cypher to get desired cyper character

for example

plain text

a               b                        c                    d

which means

array[0] has character a
array[1] has character b
array[2] has character c
array[3] has character d

key_size = 2 let example

desired output must be 


c          d           e            f             





Code:-

#include <iostream>
#include<conio.h>
using namespace std;

void main()
{
char ch[4]; //
int i = 0;
cout << "Please enter the plan text : ";
while (i<4)
{
cout << endl << "enter the letter # :" << i << endl;
cin >> ch[i];
i++;
}
char Start_ch = 'a';
char End_ch = 'z';
int KeySize = 2;

cout << "Please enter the Key Size : ";
cin >> KeySize;
char ab = 'x';

/*to get the cypher text we need to perform loop on all character present in character array*/
for (int j = 0; j<4; j++)
{
/*we initialize the variable integer with i that can start with 0 for each letter to perform logic*/
int i = 1;
while (i <= KeySize)
{
/* character is less then z letter it will remain continue*/
if (ch[j]<'z')
{
  ab = ch[j]; // get the current character from array to character variable that is temp
ab++;  //increment the array variable 1 to against keysize
ch[j] = ab;  //override the exsisting variable with increment character variable
i++;
}
/*the character who exceeds the letter z then it is reset from a to onward */
else if (ch[j] == 'z')
{
ch[j] = 'a';
i++;
}
}
}
cout << endl;
cout << "Cypher text is as under : ";
for (int i = 0; i<4; i++){
cout << ch[i];
}
_getch();
}

Output:-