You are right. i am completely new and it was my class assignment number 1. I finsihed it and submitted it already but then I came to know professionals never write everything in main that's why i decided to search in this direction. By your improved code I can see a boundery wall is set for wrong inputs. Which i wanted to set in my project as well but was not sure how to set those powerful boundaries as you set. I want to excel in this game of programming, I am not an extera ordinary student but i will keep on trying it day by day :) Following are few things I extracted from ur code which I am going to follow for the next time code or will at least try my best to do similar things. Correct me if I observed wrong. I did not follow the following things in my code. If I missed any point then point me that as well. 1) You are using braces by giving one space and starting 1st curly brace in-front of the statements like while and if. 2) All variable you wrote in small letters and to make them more clear u out _ sign to link them. 3) Function name 1st character and then the 2nd meaning name of function is capital. 3) 1 step indentation on each step involving in some kind of computation. 4) You used unsigned when you feel that value are in +ve.
Hassan Syed1
Posts
-
Large project how to seprate definition and declaration? -
Large project how to seprate definition and declaration?Excellent. Working fine now however I have to remove scanef_s. that _s was creating problem so i only remove _S and scanef remain as it. Now code working fine. Thank you for ur guidance. Now i got the clear idea how to write the code. I will copy the way you wrote this code. I am not a bad student however I like programming but problem is I think i am unable to think like a programmer. I am trying hard for that but no success yet :( I want to excel in this field but sometimes I stuck :((
-
Large project how to seprate definition and declaration?More errors :( Thank you for your guidence at least i am learning new things. Screen Shot = http://i65.tinypic.com/ncjddc.jpg[^]
-
Large project how to seprate definition and declaration?even your code giving error. Have a look at screenshot please. However, Thank you for showing me the correct way to code. I got many point out of it. Screen Shot of Error = http://i64.tinypic.com/16m0zr4.jpg
-
Large project how to seprate definition and declaration?This was the whole code from main file. Please divide it in module form like professional people do so that I can exactly see the problem in my understanding of dividing the project into moduler form
/*
Name = Syed Sibt E Hassan
Registration Number = MC160201226- Input from the user
- Function Calls to reactangle and trapezoid
- Exit loop when input is not 'Y' || 'y'
*/
#include
using namespace std;float rectangleArea (float , float); //Declaration for Rectangle Area
float trapezoidArea (float , float, float); //Declaration for Trapezoid Area.int main()
{
int choice = 0;
char tryagain = 0;
do
{
cout << "\n\nEnter 1 to calculate the area of Rectangle" << endl;
cout << "Enter 2 to calculate the area of a Trapezoid" << endl;
cout << "\n\nEnter your choice : ";
cin >> choice;
switch(choice)
{
//Dealing with area of Rectangle.
case 1:
{float width = 0.0, length = 0.0, answer = 0.0; cout << "Enter the width of rectangle :"; cin >> width; cout << "Enter the length of rectangle :"; cin >> length; answer = rectangleArea(width, length); //Function Call to Rectangle cout << "The area of Rectangle is : " << answer << endl; break; } //Dealing with area of Trapezoid. case 2: { float base1 = 0.0, base2 = 0.0, height = 0.0, answer = 0.0; cout << "Enter base1 of trapezoid : "; cin >> base1; cout << "Enter base2 of trapezoid : "; cin >> base2; cout << "Enter the height of trapezoid : "; cin >> height; answer = trapezoidArea(base1, base2, height); //Function Call to Trapezoid cout << "The area of Trapezoid is : " << answer << endl; break; } default:{ cout << "Neither 1 nor 2 entered." << endl; } } cout << "\\n Do you want to do another calculation? : "; cin >> tryagain; }while (tryagain == 'Y' || tryagain == 'y'); return
-
Large project how to seprate definition and declaration?Can i have multiple declaration files for different functions. For example; can I have a .cpp file for having input of data and can have a separate file for calculation of data? Is it a correct approach which professional follows? Actually I am confused because of declaration and definitions in septate files. When I write whole code in main it works well as soon as put the code in separate files I started getting error. I removed the .cpp file as I told above and got that concept clear that NEVER include .cpp file in .h header file. I am still getting some function calling error. I am just 1 step away to know where the problem is coming in function call. Please someone correct that portion. i already removed the break from the function as it was mentioned and also got the logical reason behind removing it. Actually I added that break in structure but as I just copy pasted the code in functions I copied it along with it :(
-
Large project how to seprate definition and declaration?Thank you everyone for your reply. Can you post in the code form like i showed in my 2nd post. If any link available about explaining this thing please share with me
-
Large project how to seprate definition and declaration?Sir please check the following. There is something wrong. If you correct it for or highlight any improvement factor it will be appreciated. Header File:
#ifndef _CALCULATION_H
#define _CALCULATION_H
#include "calculation.cpp"
#include "getinput.cpp"void input_Func(void); //Input function of text.
void input_Area(void); //Input function of Area.
void input_Trap(void); //Input function of Trapezoid.
float rectangle_Area (float , float); //Declaration for Rectangle Area.
float trapezoid_Area (float , float, float); //Declaration for Trapezoid Area.#endif
Calculation File:
#include "calculation.h"
//Calculation of Rectangle Area.
float rectangleArea (float width, float length)
{
float Area_Rectange = 0;
Area_Rectange = width * length;
return (Area_Rectange);
}//Calculation of Trapezoid Area.
float trapezoidArea (float base1, float base2, float height)
{
float Area_Trapezoid = 0;
Area_Trapezoid = ((base1 + base2)/2) * height;
return (Area_Trapezoid);
}Input data File:
#include "calculation.h"
//Dealing with the input and output of data
void input_Func(void)
{
cout << "\n\nEnter 1 to calculate the area of Rectangle" << endl;
cout << "Enter 2 to calculate the area of a Trapezoid" << endl;
cout << "\n\nEnter your choice : ";
cin >> choice;
}//Dealing with input of Rectangle float input\_Area(void) { float width = 0, length = 0, answer = 0; cout << "Enter the width of rectangle :"; cin >> width; cout << "Enter the length of rectangle :"; cin >> length; answer = rectangleArea(width, length); cout << "The area of Rectangle is : " << answer << endl; break; } //Dealing with input of Trapezoid. float input\_Trap(void) { float base1 = 0, base2 = 0, height = 0, answer = 0; cout << "Enter base1 of trapezoid : "; cin >> base1; cout << "Enter base2 of trapezoid : "; cin >> base2; cout << "Enter the height of trapezoid : "; cin >> height; answer = trapezoidArea(base1, base2, height); cout << "The area of Trapezoid is : " << answer << endl; break; }
Main File:
/*
Name = Syed Sibt E Hassan
Registration Number = MC160201226- Input
-
Large project how to seprate definition and declaration?I am new to C++ I want to define my functions declaration in a seprate header file and definitions in 2 different header files. I am saving the file with .h and .c extension in same folder where main file is located too. I also know that I have to use double quotes to include my files in main. However, I am unable to find the way to define my header file for definitions and declaration. Please give me a small example so that I can get idea about it
-
Why no boundry condition set for C++If you don't know the answer by ur-self then keep quite.
-
Why no boundry condition set for C++What is the main reason even till day-today there is no boundry condition set for C++. Why not compiler resist that we are pointing something out of the range of our array or we are pointing to a memory location which we cannot points to as it is not in the allowed range of our source code. Why not C++ creator or the IOS committee which build the standard put a check on this thing. There must be some reason of this freedom to point anywhere. I want to know that reason why they are doing like this. If a person like bjarne stroustrup can write such an advance programming language then there must be something special he left this imporant check to move in memory anywhere. If you know about this please share with me. I am curious to know the logic behind it. I asked this question from my teacher but instead of answering me he said this is not a part of my course :( I am new student to programming