C++ :: How To Modify A Program So That It Accepts Columns Instead Of Rows

Feb 4, 2015

I have a N queens (actually 8 queens to be specific) program that accepts the numbers in order by row. I need to get it so it accepts the numbers in order by column. At first glance I thought it was just one space different, but it turned out not to be and how to get the one space difference in there. My current code (which I'm aware isn't doing the column accepting right) is:

Code:

#include <iostream>
using namespace std;
int main() {
int board[8];
cout << "Enter the columns containing queens, in order by column: ";
for(int i = 0; i < 8; ++i) {
cin >> board[i];

[Code]...

What the output should be:

Code:

Enter the rows containing queens, in order by column:

7
6
5
3
4
2
1
0

.......Q
......Q.
.....Q..
...Q....
....Q...
..Q.....
.Q......
Q.......

What it is:

Code:

Enter the columns containing queens, in order by column:

7
6
5
3
4
2
1
0
........Q
.......Q.
......Q..
....Q....
.....Q...
...Q.....
..Q......
.Q.......

View 5 Replies


ADVERTISEMENT

C/C++ :: Program To Sum Rows And Columns Of A Matrix?

Apr 23, 2014

Im using apmatrix and im inputting values into a 4 by 4 matrix and im getting all these errors that have nothing to do with my cpp file so im guessing its apmatrixies fault. Also I put in the cpp and header file of both apmatrix and apvector into my project folder. Heres my code:

// Libraries
#include "apmatrix.h"
#include <iostream>
//cout, standard output
// <<, stream insertion operator

[code]....

My errors are:

error C1189: #error : The C++ Standard Library forbids macroizing keywords. Enable warning C4005 to find the forbidden macro.c:program filesmicrosoft visual studio 11.0vcincludexkeycheck.h2421TheMatrix

4IntelliSense: identifier "EMIT" is undefinedc:Program FilesMicrosoft Visual Studio 11.0VCincludeyvals.h4911TheMatrix

and a bunch are repeated

View 1 Replies View Related

C++ :: Program Inputs The Number Of Rows And Columns And Asks For The Entries

Feb 7, 2015

I am writing a program that deals with 2d arrays. The program inputs the number of rows and columns and asks for the entries. When the program run and compiles it works perfectly until it outputs then it gives me a warning.

Here is my code:

#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int row1=0,col1=0,i,j;
//int a[row1][col1];
int** a= new int*[row1];

[Code]...

I am learning how to do this before I can move on so it can read a text file of numbers.

Also I am having problems with ////delete [] a[];///// I took it out because it made my code compile and run but when I add it in, it gives me an error:

matrixtesting.cpp|56|error: expected primary-expression before ']' token|

I know this expression is suppose to deallocate the array.

View 7 Replies View Related

C :: Creating Rows And Columns

Mar 6, 2015

how to make the it all work later...but in the mean time how can i get this to display this? Note it has to be made using as a console program. The "Description" and "Cost/ib" collums will be referenced through use of a header file. all else is done by user input and calculations.

View 2 Replies View Related

C/C++ :: Columns And Rows For Loops?

Feb 26, 2015

I'm having trouble trying to get my loop program to display multiples of 4 in rows and columns. My objective is to print multiples of 4 that are less than 100 in a 4 by 4 format.

So far when I write the code I get 4 8 12 16 20 .... 96 all on the same line.

This is what I expect the code to look like if done correctly.

4 8 12 16
20 24 28 32
36 40 44 48
52 56 60 64
68 72 76 80
84 88 92 96

This is code that I have so far.

#include <iostream>
using namespace std;
int main(){

[Code]....

View 4 Replies View Related

C++ ::  how To Count Rows And Columns From File

Sep 2, 2014

So I made a text file which goes like this

word word word word
word word word word word word word
word word word word word
word word word word

(word is actually word I just didnt type them)

Now i figured out how to get the rows to work

#include <iostream>
#include <fstream>
#include <istream>
#include <stdio.h>
int main()
{
FILE* fp;
int countLines = 1;
int i;

[Code]...

I cant figure out column to work... Is it the same method cause im getting confused a lot!

View 12 Replies View Related

C++ ::  Columns And Rows In Text File

Dec 21, 2014

How i draw such a thing in .TXT file using file handling. This output must be in columns and rows and in well arranged form.

No. Name Roll No. Physic Math Compuer Science Islamiyat Pak Studies Average Grade
1 Student Name 12345 50 60 70 76 90 81 A
2 Student Name 12345 55 52 50 80 58 55 C
3 Student Name 12345 85 66 90 88 77 75 B
4 Student Name 12345 40 70 91 45 56 85 A
5 Student Name 12345 30 80 80 55 93 45 D

View 3 Replies View Related

C++ :: How To Get Sum Of Rows And Columns In 2 Dimensional Array

Aug 2, 2014

Here's my code for adding the rows and columns. My problem is that my program displays an incorrect output.

main() {
int a[20][20],r,c,y,x,sum=0,rn,cn,cs=0,rs=0;
cout<<"Enter number of columns : ";
cin>>cn;

[Code] .....

This should be the output
Enter number of columns: 4
Enter number of rows: 3
Enter twelve numbers: 9 2 3 4 2 3 1 2 5 6 7 8

The numbers are:
9234
2312
5678
Sum of number 1 column is: 16
Sum of number 2 column is: 11
Sum of number 3 column is: 11
Sum of number 4 column is: 14
Sum of number 1 row is: 18
Sum of number 2 row is: 8
Sum of number 3 row is: 26

View 6 Replies View Related

C/C++ :: How To Sort A Table By Rows / Columns

Oct 5, 2014

I am trying to sort a Report Table by which the user can enter any column or row number and output the results. And also sort by names as well. And from my code

#include "stdafx.h"
#include<iostream>
#include <string>
#include<iomanip>
using namespace std;
#include <stdlib.h> /* srand, rand */
#include <time.h> /* time */

[Code] .....

I know I need to start somewhere with a void function and put in a selection sort.

View 1 Replies View Related

C++ :: Print Square Roots Of Numbers With Rows And Columns

Mar 12, 2013

this is what i have so far

#include <iostream>
#include <cmath>
using namespace std;
int main () {
int v;

[Code] ....

im trying to get the program to print this as an example if the user enters 5 (the rounding of the decimal is optional).

1 1.41 1.73 2 2.24
1 1.41 1.73 2
1 1.41 1.73
1 1.41
1

why its not reading my for loop for rows its only doing columns ...

View 4 Replies View Related

C Sharp :: How To Select Specific Rows And Columns From A Text File

May 29, 2014

I want to select three columns from my text file i.e. Empl No, Start Date and Created Date. After selecting this, I want to insert the data into a database.

I have attached a copy of the text file.

I have the following code so far:
 
 if (File.Exists(filename))
                {  
                    string[] lines = File.ReadAllLines(filename);
                    for (int y = 0; y < lines.Length; y++) {    
                        Console.WriteLine(lines[y].ToString());  
                    }    

How do i select specific details for each employee

View 1 Replies View Related

C/C++ :: Iterate 2D Matrix In Order To Exchange Columns And Rows Using Pointers

Jan 19, 2014

I am trying to iterate a matrix in order to exchange rows and columns element by element. Although the function that exchanges the rows has come out well, i don't seem to figure out how to do the same on columns.The columns switch for a matrix like

1 2 3
1 2 3
1 2 3

if i try to switch column 3 and 2,is:

1 3 2
1 3 2
1 2 3

Here are both of the functions:

void interchange_rows(int *p,int n,int r1,int r2){
    int temp;
    for(int i=0;i<n;i++){
            temp=*(p+r1*n+i);
            *(p+r1*n+i)=*(p+r2*n+i);
            *(p+r2*n+i)=temp;
   
[Code] ......

View 1 Replies View Related

Visual C++ :: Multidimensional Array Having 3 Rows And 8 Columns - Bubble And Selection Sort

Feb 19, 2014

You will write a program that uses a multidimensional array having 3 rows and 8 columns and sorts each of the rows using both a bubble sort and a selection sort.

You must declare the array inside of main. You will have a for loop containing the calls to bubbleSort and selectionSort. You need to pass into function bubbleSort and selectionSort the following: 1) each column of the multidimensional array, 2) the size of the column, and 3) a particular row number of the multidimensional array to be used for printing out the "pass" shown on the following pages.

I keep getting an error that the identifier for bubbleSort and selectionSort is not found. (Error C3861)

Also, I feel like I'm missing something in int main() to get it to sort properly.

Code:
# include <iostream>
using namespace std;
int main() {
const int SIZE1 = 3;
const int SIZE2 = 8;
int arr [SIZE1][SIZE2] = { { 105, 102, 107, 103, 106, 100, 104, 101 },

[Code] ....

View 1 Replies View Related

C :: Array Add Total Rows And Total Columns

Apr 16, 2013

Code: i am trying to display the information in the array as a table and add the total rows and the total colums separately

#include<stdio.h>
int main(void)
{
int row, col;

[Code].....

View 1 Replies View Related

C++ :: Program That Accepts Array Of Characters

Nov 18, 2014

Here's the question: Create a program that accepts an array of characters. And displays the converted array of characters into Upper case if it is given in Lowercase and vice versa. Don't use string, but char.

Example: mychar ="I am A conQUeror."
Code: //My Codes:
#include <iostream>
#include <conio.h>
using namespace std;
int main()

[Code] ....

View 5 Replies View Related

C :: Program That Accepts First / Last Name And Displays It Through Another Function

Sep 25, 2014

I was trying to code a program that accepts your first name and then last name and then displays it through another function. I have checked that the assignments are between similar type of variables and pointers, but I don't seem to get it right.

When first input is taken and then second one, the first one's value changes to same as the second. E.G if first name is L and second name is S and after second input both variables, first and sec, become equal to S. Why?

Code:

#include <stdio.h>
#include <stdlib.h>
//FUNCTION PROTOTYPES
char *input(void);
void show(char *f,char *s);

[code]....

View 7 Replies View Related

C++ :: Program That Accepts Two Input From User?

Dec 8, 2013

I built a program that accepts two input from the user, using a array inside a loop, it is pass to a function inside a class which will display the two number, the problem is when the user is inputting a number and it is 1 the program continuously as the user to input a number, and when 2 is entered the program ask another number and end, but for example you entered 2 and 3. . . it will then outpu 2 and 4 (so 3 + 1 ) and always the last number is plus one. here is the code.

main.cpp
#include <iostream>
#include "newclass.h"
using namespace std;

[Code].....

View 5 Replies View Related

C/C++ :: Program That Accepts Information And Calculated CGPA

Jan 30, 2015

i want to display the grade report of two students in the table but this code will repeat the grade report of one student in the tables and what is wrong with this code below ?

#include<iostream>
#include<string>
#include<fstream>
using namespace std;

[Code]....

View 3 Replies View Related

C++ :: Looping Activity - Program That Accepts Positive Integer

Aug 10, 2014

You pros are once newbies like us. Hoped you might take a little time sharing your expertise. Got freaked out when our teacher gave us this activity, where she haven't taught this to us yet. So this is the activity (LOOPING) :

Write a program that accepts a positive integer. The program should be the same from the given output. Use do while to allow the user to continue or not.

OUTPUT must be:

n = 5
0
1==0
2==1==0
3==2==1==0
4==3==2==1==0
5==4==3==2==1==0

if n = 6
0
1==0
2==1==0
3==2==1==0
4==3==2==1==0
5==4==3==2==1==0
6==5==4==3==2==1==0

View 5 Replies View Related

C++ :: Program That Accepts Three Images And Combines Them Into Panoramic View

Aug 15, 2013

I've been tasked with righting a program that accepts three images and combines them into a panoramic view I'm having trouble getting started?

View 2 Replies View Related

C/C++ :: Program That Reads Data From A Text Document And Allows To Modify

Apr 30, 2015

I'm trying to make a program that reads data from a text document and allows me to modify it. I am stuck with the display() function. I can get the printf statement to display all my array values except the char AD value. When I include flight[i].AD it causes the program to crash. When I run the program to only display the AD variable I get a bunch of weird symbols. I'm not sure where the program is going wrong because it seems to be storing values properly except for the AD variable.

#include <fstream>
using namespace std;
//named constants
const int MAX=100; //maximum flights
const int SIZE=20; //maximum characters
//struct definition
struct FlightType
{
char name[SIZE];

[Code]...

View 1 Replies View Related

C# :: How To Get Program To Keep On Adding Rows To Datagrid

Jul 6, 2014

I want to be able to keep on adding a row to my datagrid every time i click a button, the row will hold the text of the text box and the combobox in its individual cells, is there a way to do this without inserting a ridiculous amount of code?

Attached image(s)

View 1 Replies View Related

C :: Program That Returns Pascal Triangle Of N Rows

Nov 25, 2013

I need to make a program that returns pascal's triangle of N rows. I actually need to make a function of format "int **func(int n)". I don't know how to go about that, so I am trying this method first, but I seem to be getting an endless loop.

Code:
#include <stdlib.h>#include <stdio.h>
int *rowN(int rowNum, int* prevRow) {
int *rowN;
rowN=realloc(rowN,(rowNum+1)*sizeof(int));

[Code] ....

View 7 Replies View Related

C :: Program To Find Mean Of Elements In Columns Which Are Divided By 3

Aug 9, 2014

The program need to find mean of elements in columns which are divided by 3. And to print which colmn has the greater mean

Example

For matrix:
7 9 5
17 15 30
29 34 60

Program print: 0 12 45. The greater mean: 3 column.

I wrote this code and it prints 0 12 45 idk how to find which column has greater mean?

Code:

#include <stdio.h>
#define max 50
int main()
{int n,m,i,j,k,d,br=0,suma;
int a[max][max];
int b[max][max];
printf("Kolku redici i kolku koloni da imat matricite: ");
scanf("%d %d ", &n,&m);

[Code]...

View 2 Replies View Related

C/C++ :: Program That Reads 3-by-4 Matrix And Displays Sum Of Columns

Nov 18, 2014

I'm not sure why Im getting a wrong Sum. of the Columns.

Write a method that returns the sum of all the elements in a specific column in a matrix using the following header:

double sumColumn(const double m[] [SIZE], int rowSize, int columnIndex)

Write a test program that reads a 3-by-4 matrix and displays the sum of each column. here is a sample run:

Enter a 3-by-4 matrix row by row:
1.5 2 3 4
5.5 6 7 8
9.5 1 3 1
Sum of the elements at column 0 is 16.5
Sum of the elements at column 1 is 9.0
Sum of the elements at column 2 is 13.0
Sum of the elements at column 3 is 13.0

#include <iostream>
using namespace std;
const int SIZE = 4;
int rowSize=3;

[Code].....

View 1 Replies View Related

C/C++ :: Program That Will Print Numbers In Columns From User Input

Oct 7, 2014

I tried to work on this program for while, but I am not able to get it to work

Directions:Write a program that reads an integer n from the user.

Display the first 100 numbers, with newlines every n numbers, using % operator

#include <stdio.h>
int main(void){
int a = 0;
int b = 99;
printf("Enter a number: ");
scanf ("%d", &a);

[Code] ....

When I run this code it asks me to enter a number. It doesn't matter what number I enter it gives me the numbers from 1 to 100 in one horizontal line.

I want this program to do something like this:

for example if the user enters n=6 the program should give:

0 1 2 3 4 5 6
7 8 9 10 11 12 13
and so on

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved