My C++ program
I'm making a program in C++ for my coomputer project..for Cambridge exams….
I got the feeling it pretty sucks… Anyone could give me ideas to make it better?????
"Supposed to be record oriented"
…Supposed to include array and a search function….
// 3.cpp : main project file. P2 Computing Project …C++
#include "stdafx.h" #include "stdlib.h" #include "time.h" #include <sys/types.h> #include <sys/timeb.h> #include <stdio.h> //Returns values to the progra fo the Date function #include <iostream> #include <string.h> using namespace std;
int main() { //main declarations char name[30]; char address[35]; char gender; char team; char project[30]; char department; float number_project_completed; float sales_pro;//sales made from the totality of projects float rank;//an assignment for the renk which the person possese within the company. The smallest number representing the most important
//Declarations for time reading and displaying
char tmpbuf[128], timebuf[26], ampm[] = "AM";
time_t ltime;
struct _timeb tstruct;
struct tm today, gmt, xmas = { 0, 0, 12, 25, 11, 93 };
errno_t err;
cout<<"\n================================================================================";
cout<<" program S.P";
cout<<"\n================================================================================";
// Set time zone from TZ (Time Zone) environment variable. If TZ is not set,
// the operating system is asked to obtain the default value
// for the variable in order to find the time.
//
_tzset();
// Displaying operating system-style date and time. in this case, that of Windows XP
_strtime_s( tmpbuf, 128 );
printf( "\n time:\t\t\t\t%s\n", tmpbuf );
_strdate_s( tmpbuf, 128 );
printf( "\n date:\t\t\t\t%s\n", tmpbuf );
cout<<"\n--------------------------------------------------------------------------------";
cout<<"\n [If a statement appears several times, then you have surely made a mistake] \n";
cout << "\n Please enter name: ";
cin >> name;
cout << "\n Please enter address: ";
cin >> address;
//Start of loop aiming at restricting values for "gender" //While loop do
{cout<<"\n Enter gender of employee:";
cout<<"Key in M for Male and F for Female: ";
cin>>gender;
} while (gender != 'f'&& gender != 'm');
if (gender == 'm' )
cout<<"\n You entered male";
else
if (gender == 'f')
cout<<"\n You entered Female";
cout << "\n ";
//Start of loop aiming at restricting values for "department" //While loop do
{cout<<"\n Enter Department. R: Research D: Development ";
cin>>department;
} while (department != 'd'&& department != 'r');
//Capital letters not considered by program
if (department == 'd' )
cout<<"\n You entered Development Department";
else
if (department == 'r')
cout<<" \n You entered Research Department";
cout<<"\n";
// Start of loop aiming at restricting values for "team"
do {cout<<"\n Enter Team. a: Team Alpha o: Team Omega "; cin>>team; } while (team != 'a'&& team != 'o');
if (team == 'a' )
cout<<"\n You entered Team Alpha";
else
if (team == 'o' )
cout<<"\n You entered Team Omega";
cout<<"\n";
cout<<"\n Enter Project the person is responsible of :";
cin>>project;
cout<<"Project name is: "<<project;
cout<<"\n Enter number of projects completed by the employee: ";
cin>>number_project_completed;
cout<<"The employee has acheived "<<number_project_completed<<" projects ";
return 0; }
It seems like it will work, I compiled it and it ran fairly smooth, I didnt notice anything wrong. The best thing is to save the source and compile.
Also, if you want to see if your doing something wrong in programming, get notepad++ it has support for pretty well all the languages and highlights syntax, and numbers lines, etc.
download it at: http://notepad-plus.sourceforge.net/uk/site.htm
Bl4ckC4t
You should be able to use some functions in there pretty easily, returning the character strings. And as for files (assuming you mean reading from files to get the information instead of command-line), you should be able to change that without changing much of the code. Would you want to get the information from one file or several files?
no offence but for a Cambridge level program, thats not the best, im a 14 year old kid ( and funnily enough live in Cambridge :P ) and that program isnt really inspiring lol, i could write better, maybe you should try something more interesting than simple cin and cout stuff (althought all the dates etc is pretty cool, i havnt seen that before).
no offence but for a Cambridge level program, thats not the best, im a 14 year old kid ( and funnily enough live in Cambridge :P ) and that program isnt really inspiring lol, i could write better, maybe you should try something more interesting than simple cin and cout stuff (althought all the dates etc is pretty cool, i havnt seen that before).