473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Detect all the possible errors in C++ code

1. #include <iostream>
2. using namespace std;

3. void generateTable(int x, int y){
4. int result = y / x;

5. for(int i = 1; i <= 10; i++){
6. cout<<result<<" * "<<i<<" = "<<i*result<<endl;
7. }
8. }

9. main(){
10. int found;
11. int data[10];
12. for(int i = 0; i < 10; i++){
13. for(int j=0; j < 10; j++){
14. found++;
15. }
16. }
17. cout<<"Loops executed "<<found<<" times"<<endl;
18. for(int i = 0; i<= 10; i++){
19. data[i] = 0;
20. }

21. int first, second;

22. cout<<"Enter first number: ";
23. cin>>first;

24. cout<<"Enter second number: ";
25. cin>>second;

26. cout<<"Subtract first number by second and show math table of resut"<<endl;

27. generateTable(first, second);

28. int rem = first%2;

29. if(rem = 0){
30. cout<<"First number is even"<<endl;
31. }
32. else{
33. cout<<"First number is odd"<<endl;
34. }
35. }
Nov 29 '17 #1
3 2183
Coupling refers to how many dependencies there are between modules and the nature of the links. Based on the nature of dependency, there are different type of coupling like data coupling, stamp coupling, content coupling and control coupling etc. You are required to identify the type of coupling that the following statements represent. Justify your answer with solid reason.
i. Module A ``branches'' or ``falls through'' into Module B (by containing a GOTO statement that transfers control somewhere into the middle of Module B).
ii. Module A refers to, or changes, Module B's internal (and, again, ``private'') data
iii. Module A changes one of the statements in Module B's object code.
Nov 29 '17 #2
You forgot to add .h at the end of upstream
Check the equality operator at line 29
Dec 1 '17 #3
donbock
2,426 Expert 2GB
  1. Lines 12-16: don’t see what this is for; what do you intend this code to do?
  2. Line 14: found hasn’t been initialized.
  3. Lines 18-20: last pass will access nonexistent location data[10].
  4. Lines 18-20: don’t see what this is for (data array never used again); what do you intend this code to do?
  5. Line 26: “Divide second number by first” instead of “Subtract first number by second”; misspelled “result”.
  6. Line 29: as noted by RGauthamRam.
  7. General: what do you want to happen when the first number (the divisor) is zero?
  8. General: do you want generateTable to always divide second number by first; or would it be more helpful to divide the larger magnitude number by the smaller magnitude number (-5 has larger magnitude than +2) so that result is never 0?
Dec 2 '17 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Aquarius2431 | last post by:
Hi!, I don't think I have posted to this group before. Have been using PHP on my webserver for a few months now and finding that I like it quite a bit. Here is a question that just occurred...
2
by: Sergio del Amo | last post by:
Hi, I wrote some functionality for a Web Page with Javascript. My code works perfectly for Firefox but not for IE. I become some errors apparently all based in the same problem wich scapes to my...
1
by: Ralph | last post by:
Hi My users are going to toggle back and forth between DataSheet and Form view. This eliminates the need for a pile of queries <g> Anyway, I would like my form to be viewed at the current size...
6
by: Einar ?rn | last post by:
Hi all, is there a good way to detect recursive C code in large systems? A method or a free tool? Best regards, E
7
by: jdn | last post by:
I have a class called myConfigurationClass with 3 private members, and 3 public gets (so, 3 read-only properties). So, for instance private members: _A, _B, _ public gets A, B, Oh, and they...
2
by: deBassMan | last post by:
Hi all Using MS Access 2000, Win XP I require a quick and dirty (or all-singing and dancing) way of detecting whether a vertical scrollbar is visible on a sub-form. apologies if posted in...
1
by: deBassMan | last post by:
Hi all Using MS Access 2000, Win XP I require a quick and dirty (or all-singing and dancing) way of detecting whether a vertical scrollbar is visible on a sub-form. apologies if posted in...
0
by: wv01 | last post by:
hello everbody, is it anyway possible to detect with VBA-code when a user exits the FAX-wizard with 'Cancel' ? many thanks in advance
14
Dököll
by: Dököll | last post by:
Greetings and salutations! Hope it's a good week thus far... Got myself thinking and wanted to see what can be achieved with a certain bit of code: public double getPayment( ) { ...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.